TypeScript SDK: route websocket errors on established connections to onDisconnect - #5707
Open
sephirith wants to merge 2 commits into
Open
TypeScript SDK: route websocket errors on established connections to onDisconnect#5707sephirith wants to merge 2 commits into
sephirith wants to merge 2 commits into
Conversation
…onDisconnect Fixes clockworklabs#5706. ws.onerror previously emitted connectError and disabled the send path for every websocket error, even mid-session, leaving the client silently stalled with no disconnect to trigger reconnect handling. Errors on an established connection now close the socket so the onclose path emits disconnect, with the error passed through per the documented onDisconnect contract. Pre-connect errors emit connectError as before.
Contributor
Author
|
@bfops @JasonAtClockwork - Thanks for merging in my last PR. Another small but important one here. Could you please review and merge? |
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.
Description of Changes
Fixes #5706.
The TypeScript SDK's
ws.onerrorhandler treats every websocket error as a connect failure: it setsisActive = falseand emitsconnectError, even when the connection was already established. On an established connection this firesonConnectError(documented as a connect-time failure callback and commonly wired to boot-time auth recovery), silently disables the outbound send path while the socket may still beOPEN(reducer and procedure calls queue with no disconnect to trigger reconnect logic), and loses the error entirely ifoncloseeventually arrives, since thedisconnectemit carried no error argument.This change tracks whether the initial connection succeeded (
InitialConnectionreceived,onConnectinvoked). A websocket error after that point no longer emitsconnectError; instead the error is recorded and the socket is closed, so the existingonclosepath emitsdisconnectand every consumer's existing reconnect handling takes over. The recorded error is passed through to thedisconnectemit, which honors the documentedonDisconnectcontract ("If the connection ended because of an error, the error is passed to the callback"). Errors before the initial connection succeeds emitconnectErrorexactly as before.API and ABI breaking changes
None.
onDisconnectcallbacks already accept an optional error argument (error?: Error | undefined); passing the error is additive and matches the documented behavior. Pre-connectconnectErrorbehavior is unchanged.Expected complexity level and risk
1 - two private fields and a gate in one method. The only behavioral change is on a code path that previously produced a silently stalled connection routed to the wrong callback; it now produces a socket close, which flows through the disconnect handling every consumer already has.
Testing
npm testincrates/bindings-typescriptpasses (289 tests, 29 files).prettier --checkpasses on the changed file.spacetimedb@2.7.1): a mid-session websocket error previously fired ouronConnectErrorlogin-recovery path while reducer calls silently queued and no reconnect ran; with this routing the socket closes,onDisconnectfires with the error, and the client reconnects normally.