pusher / pusher/pusher-websocket-react-native
onAuthorizer runs sequentially on Android
Nobody has claimed this yet.
- 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:
- Install example app from this pusher repo on Android, commit
b65a2c5fd885a2be4b1e9d1cbf9e8f5183622ef5 - 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);
- Start the app, fill in Pusher text inputs (remember to use
private-channel prefix to trigger auth!) - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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