Skip to content

fix(webrtc): Fix stale websocket on long calls - #7060

Open
rapterjet2004 wants to merge 2 commits into
masterfrom
fix/signaling-stale-websocket-call-recovery
Open

rapterjet2004 wants to merge 2 commits into
masterfrom
fix/signaling-stale-websocket-call-recovery

Conversation

@rapterjet2004

@rapterjet2004 rapterjet2004 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

🚧 TODO

  • Review it with /code-review high

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

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>
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

📱 QA build

Download app-qa-debug.apk
QR code Open the QR code for this download
Commit 7d46e89
Version 7060
Available until 7 days after this build

The QA build installs alongside a released Nextcloud app, so you can keep
using your existing install while testing.

Downloading the file requires a GitHub account, so open this link on the
device you want to test on, or transfer the APK to it.

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>
@rapterjet2004 rapterjet2004 self-assigned this Nov 18, 2026
@rapterjet2004 rapterjet2004 added the 3. to review Waiting for reviews label Nov 18, 2026
@rapterjet2004
rapterjet2004 requested a review from mahibi November 18, 2026 16:16
@github-actions

Copy link
Copy Markdown
Contributor

Codacy

Lint

TypemasterPR
Warnings1716
Errors00

SpotBugs

CategoryBaseNew
Bad practice77
Correctness88
Dodgy code4040
Internationalization33
Malicious code vulnerability33
Performance77
Security1111
Total7979

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

Labels

3. to review Waiting for reviews AI assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android Talk reuses a stale signaling WebSocket and audio calls fail until the app is restarted

1 participant