pusher / pusher/pusher-websocket-react-native

onAuthorizer runs sequentially on Android

Open
#37 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

hacktoberfest
Dominant language
TypeScript
Stars
76
Forks
64
PR merge metrics
No merged PRs in 30d

Description

Problem

See #34 – it's almost the same problem, but on Android the app is still responsive, the native thread is blocked, though.

As a result, only one subscribe authorizer can be fired at the same time, because the first call will lock the mutex (and the thread).
The next one has to wait until the first one completes and if it does not complete (unlock the mutex) then the authorization logic is completely blocked.

The possible fix is the same as on iOS – remove the logic that relies on mutex in favor of a more lightweight blocking mechanism (like this) and a timeout in case JS does never return the auth object for a given subscription.

Repro steps:

  1. Install example app from this pusher repo on Android, commit b65a2c5fd885a2be4b1e9d1cbf9e8f5183622ef5
  2. Simulate multiple subscriptions fired at the same time:

Add this in connect:

await pusher.connect();
await pusher.subscribe({ channelName });
// add the lines below to fire extra subscriptions
setTimeout(async () => {
  await pusher.subscribe({ channelName: channelName + '_1' });
}, 100);
setTimeout(async () => {
  await pusher.subscribe({ channelName: channelName + '_2' });
}, 100);

Add this in onAuthorizer:

const onAuthorizer = async (channelName: string, socketId: string) => {
// this could also be await fetch(url), but long timeout is better for repro
console.warn('start ' + channelName);
await new Promise((resolve) => setTimeout(resolve, 5000));
console.warn('end ' + channelName);
  1. Start the app, fill in Pusher text inputs (remember to use private- channel prefix to trigger auth!)
  2. Tap Connect button and check the logs (console.warns)

Expectation: We should first see 3x start log and then 3x end log
Actual: It runs sequentially – first one start, then end+start and so it goes

FWIW – it works as expected on iOS here after removing the mutexes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Android implementation of onAuthorizer and compare its synchronization with the iOS change in pull request #36. Reproduce the issue using the example app at commit b65a2c5fd885a2be4b1e9d1cbf9e8f5183622ef5 and the concurrent subscribe steps; done means multiple authorizers can run concurrently and a timeout prevents authorization from remaining blocked.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, react-native, typescript
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.