test: trail_analyze.test.ts leaks an unhandled ReadableStream rejection (Node 24) #57

Closed
opened 2026-11-05 16:41:52 +00:00 by maximus · 1 comment
Member

Running the web unit tests locally (Node 24 on spl-vm05), vitest reports 1 unhandled rejection from web/src/lib/server/trail_analyze.test.ts: ERR_INVALID_STATE / "ReadableStream is already closed" (undici). It reproduces with only that file, and all of its tests pass. Locally vitest then exits 1; CI (Node 20) stays green, e.g. on PR #52.

It was seen by four agents on 2026-11-05 (PRs #52, #54, #55, #56). It is likely a stream that is closed twice, or a response body read after cancel, in the test mocks or in the trail-analyze proxy. That is harmless under Node 20 but stricter in Node 24.

  • Reproduce under Node 24, find the double close, and fix the test or the proxy code.
  • Decide whether CI should also run Node 22/24.

🤖 Generated with Claude Code

Running the web unit tests locally (Node 24 on spl-vm05), vitest reports **1 unhandled rejection** from `web/src/lib/server/trail_analyze.test.ts`: `ERR_INVALID_STATE` / "ReadableStream is already closed" (undici). It reproduces with only that file, and all of its tests pass. Locally vitest then exits 1; CI (Node 20) stays green, e.g. on PR #52. It was seen by four agents on 2026-11-05 (PRs #52, #54, #55, #56). It is likely a stream that is closed twice, or a response body read after cancel, in the test mocks or in the trail-analyze proxy. That is harmless under Node 20 but stricter in Node 24. - [ ] Reproduce under Node 24, find the double close, and fix the test or the proxy code. - [ ] Decide whether CI should also run Node 22/24. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

Root cause found. It is a test fixture issue, not a bug in the proxy:

  • The 413 test ("stops an authorised oversized body at its own cap") built its Request from FormData. When limitedUpload (request_body.ts) hits the cap, it cancels the reader.
  • On a FormData-backed Request, Node 24's undici still enqueues the trailing multipart boundary into the cancelled stream, which throws ERR_INVALID_STATE.
  • It reproduces in 12 lines without any proxy code. Real requests arrive as socket streams, so production is unaffected.

Fix: the test uses the existing streamed() helper (a hand-built ReadableStream), plus an assertion that reading stops near the cap. Commit 82616e5d on fix/57-trail-analyze-stream, which will be shipped with the next batch. Node 24: the file passes 63/63 in 3 runs and the whole suite passes 1093 with exit 0 and no errors.

Correction: CI runs the web job on Node 22 (setup-node), not 20. Recommendation: add Node 24 as a matrix entry or a non-blocking job once the runner queue has capacity.

🤖 Generated with Claude Code

Root cause found. It is a **test fixture issue, not a bug in the proxy**: - The 413 test ("stops an authorised oversized body at its own cap") built its `Request` from `FormData`. When `limitedUpload` (`request_body.ts`) hits the cap, it cancels the reader. - On a FormData-backed `Request`, Node 24's undici still enqueues the trailing multipart boundary into the cancelled stream, which throws `ERR_INVALID_STATE`. - It reproduces in 12 lines without any proxy code. Real requests arrive as socket streams, so production is unaffected. Fix: the test uses the existing `streamed()` helper (a hand-built `ReadableStream`), plus an assertion that reading stops near the cap. Commit `82616e5d` on `fix/57-trail-analyze-stream`, which will be shipped with the next batch. Node 24: the file passes 63/63 in 3 runs and the whole suite passes 1093 with exit 0 and no errors. Correction: CI runs the web job on **Node 22** (`setup-node`), not 20. Recommendation: add Node 24 as a matrix entry or a non-blocking job once the runner queue has capacity. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jmz closed this issue 2026-11-05 18:15:50 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer#57
No description provided.