Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix state handling issue in SignalClient #1004

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

holzgeist
Copy link
Contributor

This PR solves a state handling issues in SignalClient on mobile clients (iOS in our case) when switching from mobile data to wifi.

This paragraph is an assumption from my side, feel free to correct me. When switching on Wifi, the operating system leaves the websocket connection open on mobile data to avoid reconnects. Due to high data volume, it kills the WebRTC connection though.

Now back to observations:

  • When PCTransportManager notices the lost WebRTC connection, it initiates a reconnect event, which reaches SignalClient in line 214.
  • this.state is set to RECONNECTING
  • the rest of the reconnect logic is handled in connect
  • if the websocket is still there (which it is, because it is still connected, sending pings and all), we close it in line 275
  • Here comes the bug: close sets state to DISCONNECTING and to DISCONNECTED while cleaning up the websocket
  • connect continues to setup a connection
  • the server knows about the reconnect and sends a reconnect response right after the websocket connects
  • line 358 should handle this, but only if state is still RECONNECTING
  • By ignoring this message, state is stuck in DISCONNECTED, while the rest of the system repeatedly tries to initiate a connection

The fix is to skip state update in close if we are closing the websocket as part of a reconnection (i.e. from connect). We are already connecting, no need to set the state to DISCONNECTED.

Copy link

changeset-bot bot commented Jan 24, 2024

🦋 Changeset detected

Latest commit: b99d06e

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

@lukasIO
Copy link
Contributor

lukasIO commented Jan 24, 2024

thanks for the detailed report (and fix)!
yeah, that definitely seems to be a bug in the current implementation.

@davidzhao davidzhao requested a review from lukasIO January 24, 2024 16:27
@lukasIO lukasIO merged commit bb0a1d3 into livekit:main Jan 24, 2024
3 checks passed
@github-actions github-actions bot mentioned this pull request Jan 24, 2024
lukasIO added a commit that referenced this pull request Jan 24, 2024
* Fix state handling issue in SignalClient

* Create tall-files-shop.md

---------

Co-authored-by: lukasIO <[email protected]>
@holzgeist holzgeist deleted the fix-signal-client-state branch January 25, 2024 07:50
@holzgeist
Copy link
Contributor Author

Awesome, thanks for the fast reaction and backport to v1!

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.

2 participants