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

Race condition with quick connections and disconnections #907

Open
AndyTWF opened this issue Jan 27, 2023 · 1 comment
Open

Race condition with quick connections and disconnections #907

AndyTWF opened this issue Jan 27, 2023 · 1 comment
Labels
bug Something isn't working. It's clear that this does need to be fixed.

Comments

@AndyTWF
Copy link
Contributor

AndyTWF commented Jan 27, 2023

In a situation where the library reaches the connected state and the transport almost immediately fails, it can lead to a race condition whereby the connection state is permanently in connected, even though the underlying transport is gone - without retrying the connection.

It may happen in the following order of events:

1. requestState called for connected state - is queued up on the action queue
2. Transport fails, onTransportUnavailable called, which creates a SynchronousStateChangeAction, calling setState(disconnected) immediately on construction - queues the remaining action for later
3. Connected state change processed by the action, setState(connected) called. This passes the transport checks in setState because right now the transport is still the same object, even though it's unavailable.
4. Disconnected event is processed by the queue, enactState is called here, which is the bit that finally invalidates the transport.
5. Because the state is connected, attempting to reconnect the transport will not happen

The appropriate flow should be:

  1. Check the transport associated with the disconnected event whilst performing the synchronous part. Make sure it's valid. If not, discard event.
  2. If so: synchronously make the transport null (preventing the setState of the connected action from doing anything)
  3. Set the state to disconnected
  4. And the rest of the async event processing (queue up the disconnected event)

┆Issue is synchronized with this Jira Task by Unito

@AndyTWF AndyTWF added the bug Something isn't working. It's clear that this does need to be fixed. label Jan 27, 2023
@sync-by-unito
Copy link

sync-by-unito bot commented Jan 27, 2023

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It's clear that this does need to be fixed.
Development

No branches or pull requests

1 participant