Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onAuthorizer runs sequentially on Android #37

Open
barsumek opened this issue Sep 28, 2022 · 0 comments
Open

onAuthorizer runs sequentially on Android #37

barsumek opened this issue Sep 28, 2022 · 0 comments

Comments

@barsumek
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants