Skip to content

Connection closes without recovery #22

Closed
@erquhart

Description

@erquhart

Bug

The websocket connection can quietly drop without recovery. This happens often when a native app is brought from background after token has expired, but can happen outside of this context as well.

Walkthrough

  1. Once token authenticate succeeds, a refetch is scheduled for just before the new token expires.
  2. Around the time of the scheduled refetch, the user initiates a query or mutation with the near-expired token.
  3. The server finds the token to be expired and returns an auth error.
  4. Reauthentication is attempted, which stops the websocket connection and fetches a new token.
  5. In a race condition, the scheduled refetch runs at this point, rendering the still-running reauthentication attempt outdated.
  6. The reauthentication attempt returns early due to being outdated, never restarts the connection (which would happen here).
  7. The scheduled refetch resolves, but no authentication call can be made as the connection is stopped.
  8. The scheduled refetch ends with a socket resume attempt, which does not work on stopped connections.

The socket remains closed. Authentication state is unchanged, client appears authenticated to the user.

Root cause

tryToReauthenticate() no longer restarts the socket as of this commit: 27fe643#diff-d191fc16ddb7007da8373029e3fc1610dfa34b8d95aa26652313bd672ec52699L227. A tryToReauthenticate() that is followed by a refetchToken()

This change was clearly purposeful, maybe a team member can shed some light?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions