Skip to content

[T3 Connect] TypeScript SDK: fail the connection instead of crashing Node on a bad message - #6010

Draft
bradleyshep wants to merge 1 commit into
masterfrom
bradley/ts-sdk-node-crash
Draft

bradleyshep wants to merge 1 commit into
masterfrom
bradley/ts-sdk-node-crash

Conversation

@bradleyshep

@bradleyshep bradleyshep commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of the work to move T3 Code's T3 Connect relay onto SpacetimeDB.

Description of Changes

Two kinds of error escaped the WebSocket message listener: a server message the client can't decode or apply (for example, client bindings out of step with the module's schema), and an error thrown by a user callback. Browsers only report such errors, but Node rethrows them on the next tick, which kills the host process.

This handles them the way the C# SDK already does:

  • A message that can't be applied leaves the client cache inconsistent. The inbound drain now logs it, drops the queued messages and closes the socket, so onDisconnect receives the error like any other failed connection.
  • A callback that throws (onInsert, onConnect, onApplied, …) is logged, and the remaining callbacks still run on an open connection. The cache is already up to date by the time callbacks run, so there's no reason to drop the connection. Dropping it would also make the framework providers reconnect, and the same callback would likely throw again on the re-sent rows.

Split out of #6005 / #6006.

API and ABI breaking changes

None.

Rollback safety impact

n/a

Expected complexity level and risk

  1. Behaviour changes only for errors that would already have escaped the listener. One visible difference in browsers: a callback error is now logged through the SDK's logger instead of surfacing as an uncaught error.

Testing

  • pnpm test in crates/bindings-typescript (324 passing)
  • New test: a TransactionUpdate carrying a row one byte short (standing in for bindings out of step with the module) no longer throws from the socket handler; onDisconnect receives the RangeError and the connection closes
  • New test: a throwing onConnect callback is logged, a second onConnect callback still runs, and the connection stays open
  • Both tests fail against origin/master's SDK code
  • The C# precedent: SpacetimeDBClient.cs disconnects when message parsing fails, and Table.cs / SpacetimeDBClient.cs catch and log exceptions from user callbacks
  • Limit: closing the connection doesn't settle reducer/procedure promises already in flight; callers still need their own timeouts

@bradleyshep
bradleyshep force-pushed the bradley/ts-sdk-node-crash branch 2 times, most recently from 593741b to d6aa799 Compare September 30, 2026 17:38
@bradleyshep bradleyshep changed the title TypeScript SDK: fail the connection instead of crashing Node on a bad message [T3 Connect] TypeScript SDK: fail the connection instead of crashing Node on a bad message Sep 30, 2026
…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.

This matches the C# SDK:
- A message that cannot be applied is logged, the queue is dropped and the socket closed, so onDisconnect receives the error.
- A callback that throws is logged, and the other callbacks still run on an open connection.
@bradleyshep
bradleyshep force-pushed the bradley/ts-sdk-node-crash branch from d6aa799 to 5c8d0ea Compare October 1, 2026 17:26

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant