From 95c2777d11ca0590f9089c867fee5b61fc438692 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Wed, 19 Nov 2025 09:33:03 -0800 Subject: [PATCH] chore(engine-runner): remove echo close on ToClientWebSocketClose --- engine/sdks/typescript/runner/src/tunnel.ts | 12 +++++------- .../runner/src/websocket-tunnel-adapter.ts | 19 +++++-------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/engine/sdks/typescript/runner/src/tunnel.ts b/engine/sdks/typescript/runner/src/tunnel.ts index 1d053d8420..f261ae5ffa 100644 --- a/engine/sdks/typescript/runner/src/tunnel.ts +++ b/engine/sdks/typescript/runner/src/tunnel.ts @@ -317,7 +317,7 @@ export class Tunnel { }, }); }, - (code?: number, reason?: string, hibernate: boolean = false) => { + (code?: number, reason?: string) => { // Send close through tunnel if engine doesn't already know it's closed if (!engineAlreadyClosed) { this.#sendMessage(requestId, { @@ -325,7 +325,7 @@ export class Tunnel { val: { code: code || null, reason: reason || null, - hibernate, + hibernate: false, }, }); } @@ -397,7 +397,7 @@ export class Tunnel { // TODO: Switch this with runner WS if (!this.#runner.__webSocketReady()) { this.log?.warn({ - msg: "cannot send tunnel message, socket not connected to engine", + msg: "cannot send tunnel message, socket not connected to engine. tunnel data dropped.", requestId: idToStr(requestId), message: stringifyToServerTunnelMessageKind(messageKind), }); @@ -513,10 +513,7 @@ export class Tunnel { const webSocket = actor.webSockets.get(requestIdStr); if (webSocket) { // Close the WebSocket connection - webSocket._closeWithHibernate( - 1000, - "Message acknowledgment timeout", - ); + webSocket.close(1000, "ws.ack_timeout"); // Clean up from webSockets map actor.webSockets.delete(requestIdStr); @@ -1070,6 +1067,7 @@ export class Tunnel { if (actor) { const adapter = actor.webSockets.get(requestIdStr); if (adapter) { + // We don't need to send a close response adapter._handleClose( requestId, close.code || undefined, diff --git a/engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts b/engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts index cc2369ede0..3eb7b6c068 100644 --- a/engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts +++ b/engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts @@ -65,11 +65,7 @@ export class WebSocketTunnelAdapter { /** @experimental */ public readonly request: Request, sendCallback: (data: ArrayBuffer | string, isBinary: boolean) => void, - closeCallback: ( - code?: number, - reason?: string, - hibernate?: boolean, - ) => void, + closeCallback: (code?: number, reason?: string) => void, ) { this.#tunnel = tunnel; this.#actorId = actorId; @@ -233,7 +229,7 @@ export class WebSocketTunnelAdapter { code?: number, reason?: string, ): void { - this.#closeInner(code, reason, false, true); + this.#closeInner(code, reason, true); } _handleError(error: Error): void { @@ -246,12 +242,8 @@ export class WebSocketTunnelAdapter { this.#fireEvent("error", event); } - _closeWithHibernate(code?: number, reason?: string): void { - this.#closeInner(code, reason, true, true); - } - _closeWithoutCallback(code?: number, reason?: string): void { - this.#closeInner(code, reason, false, false); + this.#closeInner(code, reason, false); } #fireEvent(type: string, event: any): void { @@ -328,7 +320,6 @@ export class WebSocketTunnelAdapter { #closeInner( code: number | undefined, reason: string | undefined, - hibernate: boolean, callback: boolean, ): void { if ( @@ -342,7 +333,7 @@ export class WebSocketTunnelAdapter { // Send close through tunnel if (callback) { - this.#closeCallback(code, reason, hibernate); + this.#closeCallback(code, reason); } // Update state and fire event @@ -500,7 +491,7 @@ export class WebSocketTunnelAdapter { } close(code?: number, reason?: string): void { - this.#closeInner(code, reason, false, true); + this.#closeInner(code, reason, true); } addEventListener(