Skip to content

fix(node): prevent body-read crashes and wire corruption#228

Merged
pi0 merged 1 commit into
mainfrom
fix/node-body-crashes
Jul 14, 2026
Merged

fix(node): prevent body-read crashes and wire corruption#228
pi0 merged 1 commit into
mainfrom
fix/node-body-crashes

Conversation

@pi0x

@pi0x pi0x commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Batch of Node-adapter crash/corruption fixes from the v1 stabilization review.

  • F1callNodeHandler's non-middleware branch had no .catch; an async handler that threw caused an unhandledRejection and the request hung forever. Now mirrors the middleware branch's .catch(reject).
  • F2 — a second text()/json() after the buffered fast path re-listened to an ended IncomingMessage and hung. Body consumption is now tracked at the srvx level and a second read rejects with TypeError: Body is unusable.
  • F3 — the _request getter wrapped the consumed stream in a native Request, throwing "… disturbed or locked" and poisoning bodyUsed / clone() / formData() / blob() / mode / referrer. bodyUsed is now served from srvx state and no native Request is materialized over a disturbed stream.
  • F5DataView view bodies sent the whole underlying ArrayBuffer while content-length was the view length, corrupting the response and leaving stray bytes in keep-alive connections. Now sliced to the view's window (Buffer.from(b.buffer, b.byteOffset, b.byteLength)).
  • GET/HEAD null-body — GET/HEAD are now always null-body per the fetch spec, regardless of what was on the wire and regardless of property-access order (raw bytes remain reachable via request.runtime.node.req).

Tests added in test/node-adapters.test.ts cover each finding (verified to fail on the unpatched source). Full suite: 858 passed, 32 skipped.

🤖 Generated with Claude Code

…adapter

Batch of Node-adapter crash/corruption fixes from the v1 stabilization review:

- F1: the non-middleware branch of callNodeHandler had no `.catch`, so an
  async handler that threw caused an unhandledRejection and never settled
  (request hung). Mirror the middleware branch's `.catch(reject)`.
- F2: a second `text()`/`json()` after the buffered fast path re-listened to
  an already-ended IncomingMessage and hung forever. Track body consumption
  at the srvx level and reject with `TypeError: Body is unusable`.
- F3: the `_request` getter wrapped the consumed stream in a native Request,
  throwing "... disturbed or locked" and poisoning `bodyUsed` / `clone()` /
  `formData()` / `blob()` / `mode` / `referrer`. Serve `bodyUsed` from srvx
  state and never materialize a native Request over a disturbed stream.
- F5: `DataView` view bodies sent the whole underlying ArrayBuffer while
  content-length was the view length, corrupting the response and leaving
  stray bytes in keep-alive connections. Slice to the view's window.
- GET/HEAD are now always null-body per the fetch spec, regardless of what
  was on the wire and regardless of property-access order.

Co-Authored-By: Claude Fable 5 <[email protected]>
@pi0x
pi0x requested a review from pi0 as a code owner July 14, 2026 11:25
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pi0x, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6b8d1a2-1b92-4cb7-aa26-c0e622477039

📥 Commits

Reviewing files that changed from the base of the PR and between f2edab1 and 84044d8.

📒 Files selected for processing (4)
  • src/adapters/_node/call.ts
  • src/adapters/_node/request.ts
  • src/adapters/_node/response.ts
  • test/node-adapters.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/node-body-crashes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/srvx@228

commit: 84044d8

@pi0
pi0 merged commit 7fb15d0 into main Jul 14, 2026
15 checks passed
@pi0
pi0 deleted the fix/node-body-crashes branch July 14, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants