From 640f74be4095f73e733b410bb7468765d2308be8 Mon Sep 17 00:00:00 2001 From: DexterKoelson <271681336+DexterKoelson@users.noreply.github.com> Date: Mon, 6 Apr 2026 16:21:41 -0700 Subject: [PATCH] fix(ts-sdk): prevent uncaught exceptions from breaking message pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The synchronous drain loop introduced in 2a8718bf1 correctly recovers from exceptions, unlike the old promise chain which silently dropped all subsequent messages after a throw. However, the recovery still deferred remaining messages until the next onmessage event. Wrap #processMessage in try/catch so each message is isolated — if one fails (e.g. from a user callback), the rest continue immediately. Also downgrade "unknown querySetId" logs from error to warn. These are benign race conditions (e.g. server responding to a failed unsubscribe after the subscription was already cleaned up) and not data corruption. --- .../src/sdk/db_connection_impl.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/bindings-typescript/src/sdk/db_connection_impl.ts b/crates/bindings-typescript/src/sdk/db_connection_impl.ts index b873b30bff6..e5ff18dde33 100644 --- a/crates/bindings-typescript/src/sdk/db_connection_impl.ts +++ b/crates/bindings-typescript/src/sdk/db_connection_impl.ts @@ -752,7 +752,7 @@ export class DbConnectionImpl this.#subscriptionManager.subscriptions.get(querySetId); if (!subscription) { stdbLogger( - 'error', + 'warn', `Received SubscribeApplied for unknown querySetId ${querySetId}.` ); return; @@ -784,7 +784,7 @@ export class DbConnectionImpl this.#subscriptionManager.subscriptions.get(querySetId); if (!subscription) { stdbLogger( - 'error', + 'warn', `Received UnsubscribeApplied for unknown querySetId ${querySetId}.` ); return; @@ -844,7 +844,7 @@ export class DbConnectionImpl this.#subscriptionManager.subscriptions.delete(querySetId); } else { stdbLogger( - 'error', + 'warn', `Received SubscriptionError for unknown querySetId ${querySetId}:`, error ); @@ -956,7 +956,15 @@ export class DbConnectionImpl const data = this.#inboundQueue[this.#inboundQueueOffset]; this.#inboundQueueOffset += 1; if (data) { - this.#processMessage(data); + try { + this.#processMessage(data); + } catch (e) { + stdbLogger( + 'error', + 'Uncaught error while processing server message:', + e + ); + } } } } finally {