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:
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
A handler whose
AsyncIterablethrows part-way through gets two different behavioursdepending 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, emitsstream:erroron the bus andwrites the encoder's
errorframe before ending the response:asReadableStream(src/http/web.ts:19) — the path every Fetch runtime takes, so Deno, Bun,workerd, and
app.fetch()on Node — does this instead:That errors the ReadableStream and nothing else. No
stream:erroron the bus, noencodeErrorframe, so:stream:errorsees zero on three of the four runtimes;event: errorexplaining it, which from theoutside 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 throwsfrom inside the generator. On
app.fetch()the rejection propagated out of.text()withnothing on the bus; on
listen()it produced the documentedevent: errorframe and thebus event. The #46 test asserts against the Node adapter for exactly this reason, which is a
workaround, not a preference.
asReadableStreamalso takes neither thebusnor the routename, so emitting requiresthreading both — the same two arguments
pipeStreamalready takes.Scope
Give
asReadableStreamthebusandnameits Node twin has, emitstream:error, andenqueue
encodeError's frame beforecontroller.error(or before closing — worth decidingwhether the stream should error at all once the error has been framed on the wire, since a
client that received an
errorevent does not also need a transport-level failure).stream:open/stream:closeare worth checking at the same time — if they are alsoNode-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.