Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jul 14, 2025

Description

@mjackson/node-fetch-server's request handler is typed as void, but internally it can reject when response stream is broken for whatever reason (e.g. when ReadableStream/TransformStream's transform, flush, pull, etc... throws).
https://github.com/mjackson/remix-the-web/blob/b5aa2ae24558f5d926af576482caf6e9b35461dc/packages/node-fetch-server/src/lib/request-listener.ts#L87

I was comparing with @hono/node-server (which is currently used by Waku) and this one swallows any stream errors internally, so the same won't happen. https://github.com/honojs/node-server/blob/cb52c36d1d5d5b68416c807ce4b231c8bc549e29/src/utils.ts#L20-L28. This difference might somehow affects this issue wakujs/waku#1521.


Okay, this is likely irrelevant for Waku.

I cannot reproduce any crash externally, but this can happen if there's a "bug" in stream handling e.g.

    responseStream = responseStream.pipeThrough(
      new TransformStream({
        flush() {
          throw new Error("boom")
        }
      }),
    );
⚠️⚠️⚠️ unhandledRejection ⚠️⚠️⚠️ Error: boom
    at Object.flush (/home/hiroshi/code/others/vite-plugin-react/packages/plugin-rsc/src/extra/ssr.tsx:50:17)
    at invokePromiseCallback (node:internal/webstreams/util:172:10)
    at Object.<anonymous> (node:internal/webstreams/util:177:23)
    at transformStreamDefaultSinkCloseAlgorithm (node:internal/webstreams/transformstream:621:43)
    at node:internal/webstreams/transformstream:379:11
    at writableStreamDefaultControllerProcessClose (node:internal/webstreams/writablestream:1162:28)
    at writableStreamDefaultControllerAdvanceQueueIfNeeded (node:internal/webstreams/writablestream:1251:5)
    at writableStreamDefaultControllerClose (node:internal/webstreams/writablestream:1218:3)
    at writableStreamClose (node:internal/webstreams/writablestream:722:3)
    at writableStreamDefaultWriterClose (node:internal/webstreams/writablestream:1091:10)

@hi-ogawa hi-ogawa changed the title fix(rsc): await web handler to avoid unhandled rejection fix(rsc): await handler to avoid unhandled rejection Jul 14, 2025
@hi-ogawa hi-ogawa changed the title fix(rsc): await handler to avoid unhandled rejection fix(rsc): await handler to avoid unhandled rejection Jul 14, 2025
@hi-ogawa hi-ogawa added the trigger: preview Trigger pkg.pr.new label Jul 14, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 14, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@vitejs/plugin-react@576
npm i https://pkg.pr.new/@vitejs/plugin-react-oxc@576
npm i https://pkg.pr.new/@vitejs/plugin-rsc@576
npm i https://pkg.pr.new/@vitejs/plugin-react-swc@576

commit: 9a5b687

@hi-ogawa hi-ogawa marked this pull request as ready for review July 14, 2025 07:54
@hi-ogawa hi-ogawa merged commit fa60127 into main Jul 14, 2025
28 checks passed
@hi-ogawa hi-ogawa deleted the 07-14-fix_rsc_await_web_handler_to_avoid_unhandled_rejection branch July 14, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

trigger: preview Trigger pkg.pr.new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants