From a936c6cb271da79fc8fd1b6298441cacfeb97315 Mon Sep 17 00:00:00 2001 From: Shobhit Gupta <123019122+shobhit26-09@users.noreply.github.com> Date: Sun, 15 Nov 2026 03:21:30 -0600 Subject: [PATCH 1/2] Report asynchronous message body write failures with context --- jsonrpc/src/common/messageWriter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonrpc/src/common/messageWriter.ts b/jsonrpc/src/common/messageWriter.ts index 817527c5b..7b542ef4d 100644 --- a/jsonrpc/src/common/messageWriter.ts +++ b/jsonrpc/src/common/messageWriter.ts @@ -155,7 +155,7 @@ export class WriteableStreamMessageWriter extends AbstractMessageWriter implemen private async doWrite(msg: Message, headers: string[], data: Uint8Array): Promise { try { await this.writable.write(headers.join(''), 'ascii'); - return this.writable.write(data); + return await this.writable.write(data); } catch (error) { this.handleError(error, msg); return Promise.reject(error); From 7afe23f8cdc56af0cf9639c9d8b6a3818d02a359 Mon Sep 17 00:00:00 2001 From: Shobhit Gupta <123019122+shobhit26-09@users.noreply.github.com> Date: Sun, 15 Nov 2026 03:21:41 -0600 Subject: [PATCH 2/2] Update messages.test.ts --- jsonrpc/src/node/test/messages.test.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/jsonrpc/src/node/test/messages.test.ts b/jsonrpc/src/node/test/messages.test.ts index a457d74da..44b5f027f 100644 --- a/jsonrpc/src/node/test/messages.test.ts +++ b/jsonrpc/src/node/test/messages.test.ts @@ -90,6 +90,30 @@ const msgpackDecoder: FunctionContentTypeDecoder = { }; suite('Messages', () => { + for (const failingWrite of [1, 2]) { + test(`Reports rejected ${failingWrite === 1 ? 'header' : 'body'} writes with message and error count`, async () => { + let writes = 0; + const error = new Error('Write failed'); + const writable = new Writable({ + write(_chunk, _encoding, callback) { + writes++; + callback(writes === failingWrite ? error : undefined); + } + }); + const writer = new StreamMessageWriter(writable); + const errors: [Error, Message | undefined, number | undefined][] = []; + writer.onError((event) => errors.push(event)); + const request: RequestMessage = { jsonrpc: '2.0', id: 1, method: 'example' }; + try { + await assert.rejects(writer.write(request), (actual) => actual === error); + assert.ok(errors.some(([actual, message, count]) => actual === error && message === request && count === 1)); + } finally { + writer.dispose(); + writable.destroy(); + } + }); + } + test('Writing', async () => { const writable = new TestWritable(); const writer = new StreamMessageWriter(writable, 'ascii'); @@ -350,4 +374,4 @@ suite('Messages', () => { readable.push('Content-Length: NaN\r\n\r\n{"jsonrpc":"2.0","id":1,"method":"example"}'); readable.push(null); }); -}); \ No newline at end of file +});