Skip to content

Ignore signal messages received after the WebSocket is closed on RN - #2173

Open
davidliu wants to merge 1 commit into
mainfrom
dl/rn_websocket_close_fix
Open

davidliu wants to merge 1 commit into
mainfrom
dl/rn_websocket_close_fix

Conversation

@davidliu

Copy link
Copy Markdown
Contributor

On React Native, messages still get received and emitted even after close (See react/react-native#59289). Web drops messages after close automatically, so it's a non issue there.

The issue this behavior surfaces is that a full reconnect that starts while the signal connection is still open gets cancelled, and the room disconnects instead of reconnecting.

  1. restartConnection sends a leave on the open signal connection. cleanupClient then closes the socket and waits up to 250ms for it to close before calling resetCallbacks().
  2. The server answers the leave with its own LeaveRequest (action: DISCONNECT, reason: CLIENT_INITIATED), which arrives during that window.
  3. Browsers drop messages once readyState isn't OPEN, so on web the reply never reaches the read loop. React Native's WebSocket dispatches them anyway.
  4. On React Native the reply reaches onLeave, which emits Disconnected and closes the engine, cancelling the restart.

Fix

WebSocketStream now enqueues messages only while ws.readyState === WebSocket.OPEN, matching browser behaviour. Nothing changes on web, where these messages were never delivered.

@changeset-bot

changeset-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9cacb05

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 115.81 KB (-0.05% 🔽)
dist/livekit-client.umd.js 125.08 KB (-0.03% 🔽)
dist/core/core.mjs 78.59 KB (+0.05% 🔺)

This branch has not been deployed

No deployments
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.

3 participants