From ff1c8615483bab25acc9cf04fb40339b0bd78812 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 5 Oct 2023 16:56:11 +0200 Subject: [PATCH] fix(webtransport): properly handle abruptly closed connections Refreshing the page with a client connected with WebTransport would trigger the following exception: > node:internal/process/promises:288 > triggerUncaughtException(err, true /* fromPromise */); > ^ > > [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "0".] { > code: 'ERR_UNHANDLED_REJECTION' > } Related: https://github.com/socketio/engine.io/issues/688 --- lib/transports/webtransport.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/transports/webtransport.ts b/lib/transports/webtransport.ts index 4f6f6877..5922fab0 100644 --- a/lib/transports/webtransport.ts +++ b/lib/transports/webtransport.ts @@ -14,7 +14,9 @@ export class WebTransport extends Transport { super({ _query: { EIO: "4" } }); const transformStream = createPacketEncoderStream(); - transformStream.readable.pipeTo(stream.writable); + transformStream.readable.pipeTo(stream.writable).catch(() => { + debug("the stream was closed"); + }); this.writer = transformStream.writable.getWriter(); (async () => {