Skip to content

Send InitRequest on dead WebSocket to trigger on_load#1360

Open
nirben82 wants to merge 1 commit intomesop-dev:mainfrom
nirben82:reconnect_dead_websocket
Open

Send InitRequest on dead WebSocket to trigger on_load#1360
nirben82 wants to merge 1 commit intomesop-dev:mainfrom
nirben82:reconnect_dead_websocket

Conversation

@nirben82
Copy link
Contributor

Update the dispatch method to check if the underlying WebSocket is dead before firing a user event. If it is dead, the client:

  1. Queues the incoming UserEvent.
  2. Sends an InitRequest that both revives the connection and triggers on_load on the server.
  3. Allows the existing dequeueEvent logic to safely fire the queued user action once the server finishes its initialization stream.

Fixes #1359

Copy link
Collaborator

@richard-to richard-to left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. Just one question which I left as a comment.

const isWebSocketDead =
this.experimentService.websocketsEnabled &&
this.webSocket &&
this.webSocket.readyState !== WebSocket.OPEN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks likes websocket ready state has 4 different states (open, opening, close, closing) (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState).

Should this only occur on close? Or is ok to have for the other three states?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket fails to trigger on_load callback after long disconnections

2 participants