Repository navigation
[T3 Connect] TypeScript SDK: fail the connection instead of crashing Node on a bad message - #6010
Conversation
593741b to
d6aa799
Compare
d6aa799 to
5c8d0ea
Compare
5c8d0ea to
273bca5
Compare
…nnot be applied A server message the client cannot decode or apply (for example, bindings out of step with the module's schema) threw out of the WebSocket message listener, as did an error thrown by a user callback. Browsers only report such errors; Node rethrows them on the next tick, which kills the host process. - A message that cannot be applied is logged and ends the connection: queued messages are dropped, calls in flight settle, and onDisconnect receives the error. - A callback that throws is logged, and the other callbacks still run on an open connection.
273bca5 to
9dbacbf
Compare
|
Is this *needed* for T3? No, but it seems like a straightforward quick-win to have either way. Stacking this with #6091 would be a really nice add. With this PR, the TypeScript SDK won't crash the process (in Node) anymore, with #6091 the TypeScript and C# SDKs will handle new DB columns added to the end by just ignoring them all together till the client bindings are updated like how the Rust SDK works. I'd recommend this (along with #6091, which is stacked on this branch). |
|
I updated the description. The breaking-changes section now says this is technically a breaking change, since an error thrown from a callback is now logged instead of thrown, and a message the SDK can't apply now ends the connection instead of crashing Node. We also clarified that crashing in |
Route a message that fails to apply through the same handler as one that fails to decode, and stop that handler from rethrowing when automatic reconnect is off. A failure before the connection is established now reaches onConnectError instead of onDisconnect, and every such failure arrives as a WebSocketProtocolError with the original error as its cause.
|
We pushed bd40ced to this branch. A message that fails to apply now goes through |
Description of Changes
In Node, a server message the SDK fails to apply, such as a row that doesn't match the client's bindings, throws out of the WebSocket listener and crashes the process. An error thrown in an app callback (
onInsert,onConnect, …) does the same.WebSocketProtocolErrorwhosecauseis the original error, throughonConnectErrorif the connection wasn't established yet and throughonDisconnectotherwise. Like master's protocol errors, it doesn't retry automatically. Without automatic reconnect, a message that fails to decode now does the same instead of throwing.The C# SDK already logs, fails pending calls and disconnects (source). An app that prefers to crash on a bad message can do so in
onDisconnectoronConnectError, and an app that wants to handle callback errors itself can wrap its own callbacks.#6091 makes the most common mismatch, an added column, readable.
API and ABI breaking changes
This is technically a breaking change, because errors that used to escape the SDK no longer do. An error thrown from an app callback is now logged instead of thrown, so global error handlers, error monitoring and test assertions inside callbacks no longer see it, and a message the SDK can't apply now ends the connection, so a Node service that relied on crashing and being restarted now stays up but disconnected unless it handles the error. We don't expect apps to rely on the old behavior, since it crashed Node processes and left browser calls hanging, and users would only notice when a callback throws or the server sends rows that don't match their bindings.
Rollback safety impact
n/a
Expected complexity level and risk
Testing
Added:
playerrow one byte short, as from bindings out of step with the module, ends the connection:onDisconnectgets aWebSocketProtocolErrorcaused by theRangeError, the pending reducer call rejects, and a later message is ignored. On master the error escapes the WebSocket listener instead.InitialConnectionis reported throughonConnectError, andonDisconnectis never called.onConnectis logged, a secondonConnectstill runs, and the connection stays open. On master the error escapes the WebSocket listener.The existing reconnect test for an incomplete subscription replay response checks that a protocol error with automatic reconnect on still ends the connection without retrying.
Not tested directly: a first message that fails to decode, because the test adapter only sends well-formed messages. It reaches the same handler as the case before
InitialConnectionabove.