Skip to content

Commit

Permalink
conditionally restart connection after refetch or reauth
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Jan 25, 2025
1 parent a590311 commit b16a044
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/browser/sync/authentication_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ export class AuthenticationManager {
hasRetried: false,
});
this.authenticate(token.value);
this._logVerbose("resuming WS after auth token fetch");
this.resumeSocket();
} else {
this.setAuthState({
state: "initialRefetch",
Expand All @@ -148,6 +146,8 @@ export class AuthenticationManager {
// Try again with `forceRefreshToken: true`
await this.refetchToken();
}
this._logVerbose("resuming WS after auth token fetch");
this.resumeSocket();
}

onTransition(serverMessage: Transition) {
Expand Down Expand Up @@ -296,12 +296,7 @@ export class AuthenticationManager {
}
this.setAndReportAuthFailed(this.authState.config.onAuthChange);
}
// Resuming in case this refetch was triggered
// by an invalid cached token.
this._logVerbose(
"resuming WS after auth token fetch (if currently paused)",
);
this.resumeSocket();
this.restartSocket();
}

private scheduleTokenRefetch(token: string) {
Expand Down
5 changes: 2 additions & 3 deletions src/browser/sync/web_socket_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,11 @@ export class WebSocketManager {
case "stopped":
break;
case "terminated":
// If we're terminating we ignore restart
return;
case "connecting":
case "ready":
case "disconnected":
throw new Error("`restart()` is only valid after `stop()`");
this.logger.warn("Restart called without stopping first");
return;
default: {
// Enforce that the switch-case is exhaustive.
const _: never = this.socket;
Expand Down

0 comments on commit b16a044

Please sign in to comment.