fix(daemon): release the diagnostics read stream when a caller hangs up
Merged
TH
4d ago+291+291+012345678901234567890123456789-7-7-0123456789
Summary
GET /sessions/<session>/requests/<requestId>/diagnostics streams the record with stream.pipe(res), which only unpipes when the caller hangs up. The read stream stayed open and leaked its descriptor.
The route keeps that shape and adds finished(res, () => stream.destroy()): any response end, hang-up or error destroys the record stream. The error listener stays from creation to close, so an abandoned open that then fails cannot reach uncaughtException and close the daemon.
Before / after
Caller destroys its socket after 64 KiB of a 32 MiB record:
- base: the stream stays open and leaks the descriptor
- head: the stream closes,
fdisnull
Caller hangs up before the record opens:
- base: the stream is never destroyed
- head: the stream is destroyed; a later
EACCESis caught
Status codes and response bytes are unchanged.
Validation
At 24e1a99795b7b611a17b25db0f675a6af9c42f24:
- focused test file: 14 passed on Node 26.11.1 and 22.12.0
- four tests fail on base: mid-download hang-up, both held-open hang-ups, caller gone before
createReadStream; the twoEACCEScases also fail on0c09e17with an uncaught exception - first-read
EIO500, open-failure 500 and full download guard existing behaviour - temporary uncommitted probes: real
EACCESanswers 500 JSON, a later read error truncates test/wire-compat: 51 passed;pnpm check:daemon-wire-compat, typecheck,oxlintandoxfmtclean- unchanged: a
stream.destroy()without an error, which no route code calls, would leave the response open
CI owns the full gate and device lanes.
š¤ Generated with Claude Code