sdk: recover reconnect on window focus and network return#5525
Open
DexterKoelson wants to merge 1 commit into
Open
sdk: recover reconnect on window focus and network return#5525DexterKoelson wants to merge 1 commit into
DexterKoelson wants to merge 1 commit into
Conversation
ConnectionManager only reconnects in response to ws.onclose/onerror plus a setTimeout backoff. Across a backgrounded or frozen tab the close event can be dropped while the event loop is suspended, and background timers are throttled or paused, so a scheduled reconnect never resumes when the window regains focus and the connection stays dead. Register visibilitychange, focus, online, and pageshow listeners (browser only). On resume, fire a stalled reconnect immediately with the backoff reset, and rebuild any socket that died silently (readyState CLOSING/CLOSED with no onclose). Adds WebSocketAdapter.readyState and DbConnectionImpl.isSocketClosed for the liveness check. Foreground half-open connections are already reaped by the server keep-alive (15s ping, 30s idle timeout), so this covers only the background-to-foreground gap.
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.
Fixes: #5524
Description of Changes
Add
visibilitychange,focus,online, andpageshowlisteners toConnectionManager(browser only). On resume, each retained connection is re-checked: a reconnect whose backoff timer stalled is fired immediately with the backoff reset, and a socket that died silently (readyStateCLOSING/CLOSED with noonclose) is torn down and rebuilt.Supporting changes:
WebSocketAdaptergains an optionalreadyStatemember; the decompress and test adaptersimplement it.
DbConnectionImplgains a publicisSocketClosedgetter used by the liveness check.Scope: foreground half-open connections are already reaped by the server keep-alive (15s ping, 30s idle timeout in
client-api), so this covers only the background-to-foreground gap. No client heartbeat is added; the server ping/pong is a WebSocket control frame and is not visible to browser JS.API and ABI breaking changes
None.
WebSocketAdapter.readyStateis added as an optional member, so existing custom adapters supplied throughwithWSFnstay valid without changes.DbConnectionImpl.isSocketClosedis additive, and the two built-in adapters implementreadyState.Expected complexity level and risk
The change is confined to the React connection manager and the websocket adapter interface. It reuses the existing rebuild path, so reconnect semantics are unchanged apart from being triggered on resume. Listeners are only registered when
window/documentexist, so Node and SSR are unaffected.Testing
tests/connection_manager_liveness.test.tscover resume-triggeredreconnect, zombie-socket rebuild, backoff reset, and the no-op cases (healthy connection,
intentional disconnect, tab still hidden). (FYI, the tests were totally vibe coded)
connection_managerand reconnect suites still pass.