Skip to content

Commit 556b074

Browse files
NathanFlurryMasterPtato
authored andcommitted
chore(engine-runner): remove echo close on ToClientWebSocketClose
1 parent debe04e commit 556b074

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

engine/sdks/typescript/runner/src/tunnel.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,15 @@ export class Tunnel {
317317
},
318318
});
319319
},
320-
(code?: number, reason?: string, hibernate: boolean = false) => {
320+
(code?: number, reason?: string) => {
321321
// Send close through tunnel if engine doesn't already know it's closed
322322
if (!engineAlreadyClosed) {
323323
this.#sendMessage(requestId, {
324324
tag: "ToServerWebSocketClose",
325325
val: {
326326
code: code || null,
327327
reason: reason || null,
328-
hibernate,
328+
hibernate: false,
329329
},
330330
});
331331
}
@@ -397,7 +397,7 @@ export class Tunnel {
397397
// TODO: Switch this with runner WS
398398
if (!this.#runner.__webSocketReady()) {
399399
this.log?.warn({
400-
msg: "cannot send tunnel message, socket not connected to engine",
400+
msg: "cannot send tunnel message, socket not connected to engine. tunnel data dropped.",
401401
requestId: idToStr(requestId),
402402
message: stringifyToServerTunnelMessageKind(messageKind),
403403
});
@@ -513,10 +513,7 @@ export class Tunnel {
513513
const webSocket = actor.webSockets.get(requestIdStr);
514514
if (webSocket) {
515515
// Close the WebSocket connection
516-
webSocket._closeWithHibernate(
517-
1000,
518-
"Message acknowledgment timeout",
519-
);
516+
webSocket.close(1000, "ws.ack_timeout");
520517

521518
// Clean up from webSockets map
522519
actor.webSockets.delete(requestIdStr);
@@ -1070,6 +1067,7 @@ export class Tunnel {
10701067
if (actor) {
10711068
const adapter = actor.webSockets.get(requestIdStr);
10721069
if (adapter) {
1070+
// We don't need to send a close response
10731071
adapter._handleClose(
10741072
requestId,
10751073
close.code || undefined,

engine/sdks/typescript/runner/src/websocket-tunnel-adapter.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ export class WebSocketTunnelAdapter {
6565
/** @experimental */
6666
public readonly request: Request,
6767
sendCallback: (data: ArrayBuffer | string, isBinary: boolean) => void,
68-
closeCallback: (
69-
code?: number,
70-
reason?: string,
71-
hibernate?: boolean,
72-
) => void,
68+
closeCallback: (code?: number, reason?: string) => void,
7369
) {
7470
this.#tunnel = tunnel;
7571
this.#actorId = actorId;
@@ -233,7 +229,7 @@ export class WebSocketTunnelAdapter {
233229
code?: number,
234230
reason?: string,
235231
): void {
236-
this.#closeInner(code, reason, false, true);
232+
this.#closeInner(code, reason, true);
237233
}
238234

239235
_handleError(error: Error): void {
@@ -246,12 +242,8 @@ export class WebSocketTunnelAdapter {
246242
this.#fireEvent("error", event);
247243
}
248244

249-
_closeWithHibernate(code?: number, reason?: string): void {
250-
this.#closeInner(code, reason, true, true);
251-
}
252-
253245
_closeWithoutCallback(code?: number, reason?: string): void {
254-
this.#closeInner(code, reason, false, false);
246+
this.#closeInner(code, reason, false);
255247
}
256248

257249
#fireEvent(type: string, event: any): void {
@@ -328,7 +320,6 @@ export class WebSocketTunnelAdapter {
328320
#closeInner(
329321
code: number | undefined,
330322
reason: string | undefined,
331-
hibernate: boolean,
332323
callback: boolean,
333324
): void {
334325
if (
@@ -342,7 +333,7 @@ export class WebSocketTunnelAdapter {
342333

343334
// Send close through tunnel
344335
if (callback) {
345-
this.#closeCallback(code, reason, hibernate);
336+
this.#closeCallback(code, reason);
346337
}
347338

348339
// Update state and fire event
@@ -500,7 +491,7 @@ export class WebSocketTunnelAdapter {
500491
}
501492

502493
close(code?: number, reason?: string): void {
503-
this.#closeInner(code, reason, false, true);
494+
this.#closeInner(code, reason, true);
504495
}
505496

506497
addEventListener(

0 commit comments

Comments
 (0)