block refetching when reauthenticating after an error #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
The socket remains closed. Authentication state is unchanged, client appears authenticated to the user.
Root cause
tryToReauthenticate()
only runs in response to auth errors,refetchToken()
is general purpose - for initialization and preemptive reauth.tryToReauthenticate()
stops the connection and restarts at the end,refetchToken()
does not. Both functions wait for token refetch and will bail if another token refetch (from either function) has started during the wait. IfrefetchToken()
runs whiletryToReauthenticate()
is fetching, this bug occurs, astryToReauthenticate()
has stopped the connection and will bail before restarting, andrefetchToken()
does not restart the connection (nor should it).This solution
This solution blocks any calls to
refetchToken()
from running iftryToReauthenticate()
has started and has not yet succeeded.Other solutions considered
We could schedule refetches sooner to help close the race condition gap here, but there's still no guarantee it won't occur. The chosen solution seemed closer to root cause.