From be130ffb87f2f2751b310c84bd39984db36959f9 Mon Sep 17 00:00:00 2001 From: Rohan Ranjan Prasad <149056080+rohanranjan0902@users.noreply.github.com> Date: Sat, 19 Sep 2026 14:51:36 +0530 Subject: [PATCH 1/2] fix(testing): recover from lock poisoning in memoized! macro (fixes #5841) When a previous test panics while compiling a module, the cache Mutex becomes poisoned. This replaces .unwrap() with .unwrap_or_else() to recover the lock, ensuring subsequent tests surface their actual underlying errors rather than failing with a cascade of generic PoisonErrors. --- crates/testing/src/sdk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/testing/src/sdk.rs b/crates/testing/src/sdk.rs index eb45353aa2b..7bdd5803f67 100644 --- a/crates/testing/src/sdk.rs +++ b/crates/testing/src/sdk.rs @@ -155,7 +155,7 @@ macro_rules! memoized { MEMOIZED .lock() - .unwrap() + .unwrap_or_else(|e| e.into_inner()) .get_or_insert_default() .entry(($($key_tuple,)*)) .or_insert_with_key(|($($key_tuple,)*)| -> $value_ty { $body }) From 2daa03b0093186c7fcaf752fecfad74f0530b86d Mon Sep 17 00:00:00 2001 From: Rohan Ranjan Prasad <149056080+rohanranjan0902@users.noreply.github.com> Date: Mon, 26 Oct 2026 12:38:42 +0530 Subject: [PATCH 2/2] Fix procedure error rejection type --- .../src/sdk/db_connection_impl.ts | 20 +++++-- .../tests/binary_read_write.test.ts | 38 ++++++++++++ .../tests/db_connection.test.ts | 60 +++++++++++++++++++ 3 files changed, 113 insertions(+), 5 deletions(-) diff --git a/crates/bindings-typescript/src/sdk/db_connection_impl.ts b/crates/bindings-typescript/src/sdk/db_connection_impl.ts index cf73bc270bb..991ac0029c5 100644 --- a/crates/bindings-typescript/src/sdk/db_connection_impl.ts +++ b/crates/bindings-typescript/src/sdk/db_connection_impl.ts @@ -568,7 +568,18 @@ export class DbConnectionImpl const { primaryKeyColName, primaryKeyColType } = this.#rowIdMetadata[tableName]; let previousOffset = 0; - while (reader.remaining > 0) { + const rowCount = + rowList.sizeHint.tag === 'RowOffsets' + ? rowList.sizeHint.value.length + : rowList.sizeHint.value > 0 + ? Math.floor(buffer.length / rowList.sizeHint.value) + : undefined; + + for ( + let i = 0; + rowCount === undefined ? reader.remaining > 0 : i < rowCount; + i++ + ) { const row = deserializeRow(reader); let rowId: ComparablePrimitive | undefined = undefined; if (primaryKeyColName !== undefined && primaryKeyColType !== undefined) { @@ -577,9 +588,7 @@ export class DbConnectionImpl row[primaryKeyColName] ); } else { - // Get a view of the bytes for this row. const rowBytes = buffer.subarray(previousOffset, reader.offset); - // Convert it to a base64 string, so we can use it as a map key. const asBase64 = fromByteArray(rowBytes); rowId = asBase64; } @@ -591,6 +600,7 @@ export class DbConnectionImpl row, }); } + return rows; } @@ -1289,7 +1299,7 @@ export class DbConnectionImpl if (result.tag === 'Ok') { resolve(result.value); } else { - reject(result.value); + reject(new InternalError(result.value)); } }); return promise; @@ -1313,7 +1323,7 @@ export class DbConnectionImpl if (result.tag === 'Ok') { resolve(result.value); } else { - reject(result.value); + reject(new InternalError(result.value)); } }); return promise; diff --git a/crates/bindings-typescript/tests/binary_read_write.test.ts b/crates/bindings-typescript/tests/binary_read_write.test.ts index fd4933d56f1..a6a5c1d4991 100644 --- a/crates/bindings-typescript/tests/binary_read_write.test.ts +++ b/crates/bindings-typescript/tests/binary_read_write.test.ts @@ -153,8 +153,46 @@ describe('BinaryReader/Writer', () => { const deserializedTransactionUpdate = ServerMessage.deserialize( new BinaryReader(rawBytes) ); + expect(deserializedTransactionUpdate).toEqual(transactionUpdate); }); + + test('round-trips a zero-sized row list encoded with row offsets', () => { + const rowList = { + sizeHint: RowSizeHint.RowOffsets([0n]), + rowsData: new Uint8Array([]), + }; + + const transactionUpdate = ServerMessage.TransactionUpdate({ + querySets: [ + { + querySetId: { id: 0 }, + tables: [ + { + tableName: 'empty', + rows: [ + TableUpdateRows.PersistentTable({ + inserts: rowList, + deletes: { + sizeHint: RowSizeHint.RowOffsets([]), + rowsData: new Uint8Array([]), + }, + }), + ], + }, + ], + }, + ], + }); + + const writer = new BinaryWriter(1024); + ServerMessage.serialize(writer, transactionUpdate); + const rawBytes = writer.getBuffer(); + const deserialized = ServerMessage.deserialize(new BinaryReader(rawBytes)); + + expect(deserialized.tag).toBe('TransactionUpdate'); + expect(deserialized).toEqual(transactionUpdate); + }); }); describe('readUInt8Array buffer ownership', () => { diff --git a/crates/bindings-typescript/tests/db_connection.test.ts b/crates/bindings-typescript/tests/db_connection.test.ts index ae4fa365032..a3843cbdecc 100644 --- a/crates/bindings-typescript/tests/db_connection.test.ts +++ b/crates/bindings-typescript/tests/db_connection.test.ts @@ -6,6 +6,7 @@ import { InternalError, SenderError, Timestamp, + TimeDuration, type Infer, } from '../src'; import { ServerMessage } from '../src/sdk/client_api/types'; @@ -80,6 +81,18 @@ function getLastCallReducerRequestId(wsAdapter: WebsocketTestAdapter): number { throw new Error('No CallReducer message found in messageQueue.'); } +function getLastCallProcedureRequestId( + wsAdapter: WebsocketTestAdapter +): number { + for (let i = wsAdapter.outgoingMessages.length - 1; i >= 0; i--) { + const message = wsAdapter.outgoingMessages[i]; + if (message.tag === 'CallProcedure') { + return message.value.requestId; + } + } + throw new Error('No CallProcedure message found in messageQueue.'); +} + function getLastSubscribeMessageInfo(wsAdapter: WebsocketTestAdapter): { requestId: number; querySetId: number; @@ -603,6 +616,53 @@ describe('DbConnection', () => { ); }); + test('procedure internal error rejects with InternalError', async () => { + const wsAdapter = new WebsocketTestAdapter(); + const onConnectPromise = new Deferred(); + const client = DbConnection.builder() + .withUri('ws://127.0.0.1:1234') + .withDatabaseName('db') + .withWSFn(wsAdapter.openWebSocket) + .onConnect(() => { + onConnectPromise.resolve(); + }) + .build(); + + await client['wsPromise']; + wsAdapter.acceptConnection(); + wsAdapter.sendToClient( + ServerMessage.InitialConnection({ + identity: anIdentity, + token: 'a-token', + connectionId: ConnectionId.random(), + }) + ); + await onConnectPromise.promise; + + const procedurePromise = client.callProcedure( + 'test_procedure', + new Uint8Array() + ); + await Promise.resolve(); + const requestId = getLastCallProcedureRequestId(wsAdapter); + wsAdapter.sendToClient( + ServerMessage.ProcedureResult({ + requestId, + timestamp: new Timestamp(0n), + totalHostExecutionDuration: new TimeDuration(0n), + status: { + tag: 'InternalError', + value: 'internal procedure test error', + }, + }) + ); + + await expect(procedurePromise).rejects.toBeInstanceOf(InternalError); + await expect(procedurePromise).rejects.toThrow( + 'internal procedure test error' + ); + }); + /* test('it calls onInsert callback when a record is added with a subscription update and then with a transaction update', async () => { const wsAdapter = new WebsocketTestAdapter();