A mid-stream throw is reported on Node and silent on every other runtime #83

Closed
opened 2026-09-01 16:47:35 +00:00 by chrnx · 0 comments
Owner

A handler whose AsyncIterable throws part-way through gets two different behaviours
depending on the adapter, and the one most apps are moving toward is the silent one.

What happens

pipeStream (src/http/stream.ts) catches the throw, emits stream:error on the bus and
writes the encoder's error frame before ending the response:

} catch (err) {
  bus?.emit('stream:error', { name, error: err });
  const frame = encoder.encodeError(err);
  if (frame && !res.writableEnded) res.write(frame);
}

asReadableStream (src/http/web.ts:19) — the path every Fetch runtime takes, so Deno, Bun,
workerd, and app.fetch() on Node — does this instead:

} catch (err) {
  controller.error(err);
}

That errors the ReadableStream and nothing else. No stream:error on the bus, no
encodeError frame, so:

  • an observability consumer counting stream:error sees zero on three of the four runtimes;
  • the client gets a truncated body with no event: error explaining it, which from the
    outside is indistinguishable from a clean end of stream.

The second one is the worse half. A consumer that finished normally and a consumer whose
producer blew up look identical, which is the same class of silent failure as #46.

How it was found

Writing the injection test for #46: a handler yielding an sse() with an illegal id throws
from inside the generator. On app.fetch() the rejection propagated out of .text() with
nothing on the bus; on listen() it produced the documented event: error frame and the
bus event. The #46 test asserts against the Node adapter for exactly this reason, which is a
workaround, not a preference.

asReadableStream also takes neither the bus nor the route name, so emitting requires
threading both — the same two arguments pipeStream already takes.

Scope

Give asReadableStream the bus and name its Node twin has, emit stream:error, and
enqueue encodeError's frame before controller.error (or before closing — worth deciding
whether the stream should error at all once the error has been framed on the wire, since a
client that received an error event does not also need a transport-level failure).

stream:open / stream:close are worth checking at the same time — if they are also
Node-only, then every stream gauge in the docs is Node-only and the observability guide
should not be promising them per-runtime.

Related

Found while implementing #46. Not a regression: both paths have behaved this way since the
Fetch adapter landed.

A handler whose `AsyncIterable` throws part-way through gets two different behaviours depending on the adapter, and the one most apps are moving toward is the silent one. ## What happens `pipeStream` (`src/http/stream.ts`) catches the throw, emits `stream:error` on the bus and writes the encoder's `error` frame before ending the response: ```ts } catch (err) { bus?.emit('stream:error', { name, error: err }); const frame = encoder.encodeError(err); if (frame && !res.writableEnded) res.write(frame); } ``` `asReadableStream` (`src/http/web.ts:19`) — the path every Fetch runtime takes, so Deno, Bun, workerd, and `app.fetch()` on Node — does this instead: ```ts } catch (err) { controller.error(err); } ``` That errors the ReadableStream and nothing else. No `stream:error` on the bus, no `encodeError` frame, so: - an observability consumer counting `stream:error` sees zero on three of the four runtimes; - the client gets a truncated body with no `event: error` explaining it, which from the outside is indistinguishable from a clean end of stream. The second one is the worse half. A consumer that finished normally and a consumer whose producer blew up look identical, which is the same class of silent failure as #46. ## How it was found Writing the injection test for #46: a handler yielding an `sse()` with an illegal id throws from inside the generator. On `app.fetch()` the rejection propagated out of `.text()` with nothing on the bus; on `listen()` it produced the documented `event: error` frame and the bus event. The #46 test asserts against the Node adapter for exactly this reason, which is a workaround, not a preference. `asReadableStream` also takes neither the `bus` nor the route `name`, so emitting requires threading both — the same two arguments `pipeStream` already takes. ## Scope Give `asReadableStream` the `bus` and `name` its Node twin has, emit `stream:error`, and enqueue `encodeError`'s frame before `controller.error` (or before closing — worth deciding whether the stream should error at all once the error has been framed on the wire, since a client that received an `error` event does not also need a transport-level failure). `stream:open` / `stream:close` are worth checking at the same time — if they are also Node-only, then every stream gauge in the docs is Node-only and the observability guide should not be promising them per-runtime. ## Related Found while implementing #46. Not a regression: both paths have behaved this way since the Fetch adapter landed.
chrnx closed this issue 2026-09-04 13:32:30 +00:00
Sign in to join this conversation.