From 5de65939a0923e18276724c9097df5ae39390052 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 8 Jan 2025 13:39:18 -0500 Subject: [PATCH] websocket: do not close when protocol supports it This commit updates the WebSocket handler to not call ws.close() when stdin is closed but the ws protocol already supports closing (v5 protocol for example). --- src/web-socket-handler.ts | 1 + src/web-socket-handler_test.ts | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/web-socket-handler.ts b/src/web-socket-handler.ts index 3ad71dbb55..6772427dc1 100644 --- a/src/web-socket-handler.ts +++ b/src/web-socket-handler.ts @@ -96,6 +96,7 @@ export class WebSocketHandler implements WebSocketInterface { buff.writeUint8(this.CloseStream, 0); buff.writeUint8(this.StdinStream, 1); ws.send(buff); + return; } ws.close(); }); diff --git a/src/web-socket-handler_test.ts b/src/web-socket-handler_test.ts index d652252e45..b6e7f92f34 100644 --- a/src/web-socket-handler_test.ts +++ b/src/web-socket-handler_test.ts @@ -404,8 +404,10 @@ describe('V5 protocol support', () => { send: (data) => { sent = data; }, - close: () => {}, - } as WebSocket; + close: () => { + throw new Error('should not be called'); + }, + } as unknown as WebSocket; const stdinStream = new ReadableStreamBuffer(); WebSocketHandler.handleStandardInput(ws, stdinStream); stdinStream.emit('end');