anycable / anycable-client

AnyCable / Action Cable JavaScript client for web, Node.js & React Native
MIT License
92 stars 15 forks source link

Unsubscribe/subscribe race conditions #15

Closed palkan closed 2 years ago

palkan commented 2 years ago

Original issue: https://github.com/anycable/anycable-go/issues/148

Relevant Action Cable PR: https://github.com/rails/rails/pull/41581

palkan commented 2 years ago

Fixed and released in @anycable/core@0.3.5 /cc @tleish

laznic commented 2 years ago

Sorry to bump this issue, however should these options be passable to the created cable? I checked the source where the cable is created, and the protocol isn't passed on any options. This means that the retry interval is always 5 seconds.

palkan commented 2 years ago

You can pass a custom protocol instance if you want to customize the options: createCable({protocol: new ActionCableProtocol(options)}).

This means that the retry interval is always 5 seconds.

That's the amount of time we wait for a subscription confirmation or rejection. Since Action Cable doesn't provide any feedback if the subscribe command has failed, we should rely on timeouts.

Here we try to resolve the potential race condition with unsubscription only. And we already have a different, cooldown, mechanism for that, which should work in most cases. Only if it doesn't work, we activate this retry mechanism.