Repository navigation
fix(webrtc): Fix stale websocket on long calls - #7060
Open
rapterjet2004 wants to merge 2 commits into
Open
rapterjet2004 wants to merge 2 commits into
rapterjet2004 wants to merge 2 commits into
Conversation
Root cause (the exact chain from the report's log)
A reused signaling instance can report isConnected == true while its socket is actually half-open. On that stale-true socket:
1. CallActivity trusts isConnected and calls joinRoomWithRoomTokenAndSession without waiting for a fresh hello.
2. sendMessage takes the "connected" branch: internalWebSocket.send(join) — okhttp buffers it and returns true on a dead socket, so the join is silently lost, not queued, not retried.
3. ~30s later the ping fails → reconnect → hello resumes the session (carries oldResumeId).
4. CallActivity's hello handler does nothing on a resume (if (!containsKey("oldResumeId")) is false) — it assumes a resumed session is still in its room.
5. But the join never reached the server, so we're resumed-yet-not-in-the-room. roomJoined never arrives → call hangs until the app is restarted. Exactly the reported symptom and log.
The key insight: the join was fire-and-forget — the instance never persisted which room the UI wanted, so it couldn't re-assert it after recovery.
The fix (state-driven join re-assertion)
1. Persist the desired room in a new requestedRoomToken (set on join, cleared on leave / no_such_room). This is distinct from currentRoomToken, which is only the server-confirmed room.
2. After a resumed hello, maybeResendRequestedRoomJoin() re-sends the join iff the resumed session isn't confirmed in the requested room (requested != currentRoomToken). This recovers the lost join automatically. It deliberately fires only on resume — on a fresh session the existing hello-event path already re-joins, so acting here would double-join.
3. Hardening (report's candidate A): gated the "join locally without sending" shortcut on isConnected, so a dead socket can't falsely report a local roomJoined without any server round-trip.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Julius Linus <juliuslinus1@gmail.com>
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
Contributor
📱 QA build
The QA build installs alongside a released Nextcloud app, so you can keep Downloading the file requires a GitHub account, so open this link on the |
Clear requestedRoomToken when the server takes the client out of the room, so a later session resume does not re-send a join for a room the server deliberately removed the client from. Mark requestedRoomToken @volatile: it is written on the caller thread and read on the WebSocket reader thread, so the reader must observe the current value. Assisted-by: Claude Code:claude-opus-4-8 Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
Contributor
8 of 11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Root cause (the exact chain from the report's log)
A reused signaling instance can report isConnected == true while its socket is actually half-open. On that stale-true socket:
The key insight: the join was fire-and-forget — the instance never persisted which room the UI wanted, so it couldn't re-assert it after recovery.
The fix (state-driven join re-assertion)
Assisted-by: Claude Code:claude-opus-5-5
🚧 TODO
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)