Repository navigation
Keep a hidden tab's socket open, and hold presence sent during subscribe - #1815
Closed
michielbdejong wants to merge 1 commit into
Closed
michielbdejong wants to merge 1 commit into
michielbdejong wants to merge 1 commit into
Conversation
A hidden tab's timers fire about once a minute, so the 5 s liveness check first saw a quiet socket after 60 s of silence, past the 45 s deadline, and closed it without ever sending the KEEPALIVE probe. The client now closes only when a probe it sent has gone unanswered for 25 s, measured from when it was sent. After a reconnect the client subscribes to drive presence and announces itself straight away. The server's subscribe runs an async read check and keeps handling messages meanwhile, so the announcement arrived before the connection counted as a subscriber: it was dropped with "presence update from non-subscriber". The server now holds the latest update from a connection whose subscribe is still being checked, delivers it once the check passes, and drops it if the check fails. Closes #1800 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Landed on develop in 46562ff via the combined batch #1828 (green on Mancave, run 4639). Closing. Generated by Claude Code |
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.
Closes #1800
Two separate causes, both seen in the 25 Sep user-testing session.
The connection dropped while the tab was hidden
The client's liveness check (
browser/lib/src/liveness.ts) runs every 5 s: after 20 s of silence it sends aKEEPALIVEprobe, and after 45 s of silence it closed the socket, probe or not. In a hidden tab Chrome batches timers to once a minute. The first check after the socket went quiet then saw about 60 s of silence, past the deadline, and closed a healthy connection without ever probing the server. The log line said "probe unanswered", but no probe had been sent.The evidence fits: every close in
ux.jsonlfalls at:24.6past the minute (09:03:24, 09:28:24, 09:37:24, 09:39:24 and so on), which is the throttled cadence. The server logged no drop of its own, and the browser answers the server's protocol pings outside the throttled timers.Fix: silence alone never closes the socket. The client closes only when a probe it sent has gone unanswered for
LIVENESS_PROBE_TIMEOUT_MS(25 s), counted from when it was sent. Socket events are not throttled, so the echo still resets the state between two throttled ticks. A dead socket still closes, one tick after its probe times out."presence update from non-subscriber" after reconnect
On every (re)connect the client sends
PRESENCE_SUBSCRIBEand immediately rebroadcasts its presence. The server'sSubscribePresencehandler is aResponseActFuture: it awaits a store read for the drive check, and theCommitMonitorkeeps handling messages meanwhile. So the rebroadcast arrived before the connection was in the subscriber map. It was logged as "non-subscriber" and dropped, and peers did not see the tab until its next heartbeat.Fix:
CommitMonitorrecords the subscribe as pending before the check yields. It holds the latest update from a pending connection, and delivers it (cache, peers and fan-out) when the check passes, or drops it when the check fails, the socket closes or the connection unsubscribes. An update from a connection that never subscribed still warns and is still refused.Tests
browser/lib/src/liveness.test.ts: replays the timer loop at a once-a-minute cadence against a server that answers every probe. With the old rule the first tick returnedclose. Also covers the normal cadence, and a dead socket still closing (['probe', 'close']).server/tests/it/drive_presence.rspresence_sent_right_after_subscribe_is_delivered: an update sent right behindPRESENCE_SUBSCRIBEreaches the other subscriber on the first try, over 5 reconnects, and an update held for a refused subscribe is not relayed. It fails ondevelop(round 0:None) and passes with the fix.cargo test -p atomic-server --test it drive_presence(3 tests) andws_auth_gate(12 tests) pass. Thebrowser/libliveness and WS tests pass.Docs (
docs/src/websockets.mdLiveness) andTESTING_COVERAGE.mdare updated. No UI change, so there are no screenshots.🤖 Generated with Claude Code