From e9357efb5ca06ad7a15b4e87e437835a368cbc67 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Thu, 9 Jul 2026 17:17:20 -0500 Subject: [PATCH] fix(deno): guard fire-and-forget app.upgrade against fatal unhandled rejection Signed-off-by: Diego Resendez --- src/deno.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/deno.ts b/src/deno.ts index f0d6e9b..008653e 100644 --- a/src/deno.ts +++ b/src/deno.ts @@ -99,9 +99,17 @@ export function serveDeno(app: App, options?: DenoServeOptions): DenoHttpServer return Deno.serve(options ?? {}, (request, info) => { if (request.headers.get('upgrade')?.toLowerCase() === 'websocket') { const { socket, response } = Deno.upgradeWebSocket(request); - // fire-and-forget: the graph runs after we return the upgrade response. - // runWsConnection swallows its own errors (closeOnError), so nothing escapes. - void app.upgrade(toWsRequest(request, info), denoSocket(socket)); + // Fire-and-forget: the upgrade response must be returned synchronously while + // the graph runs. app.upgrade can reject BEFORE runWsConnection's own try/catch + // (mesh-before-listen throw, or a provider boot failure), so guard the call here — + // an uncaught rejection would be fatal on Deno and crash the whole server. + void app.upgrade(toWsRequest(request, info), denoSocket(socket)).catch(() => { + try { + socket.close(1011, 'internal error'); + } catch { + /* already closed */ + } + }); return response; }