Skip to content

NodeRequest.arrayBuffer() throws a bare TypeError (not AbortError) after a client disconnect #293

Closed

Description

@EmilEinarsen

Version: srvx 0.11.22, Node v24.18.1, HTTP/2 (Http2ServerRequest/Http2ServerResponse, via the TanStack Start vite dev middleware).

What happens: a handler that does await request.arrayBuffer() on a NodeRequest gets a TypeError — not an AbortError — when the client cancels the stream while the handler is in flight:

TypeError: Response body object should not be disturbed or locked
    at extractBody (node:internal/deps/undici/undici:6919:17)
    at new Request (node:internal/deps/undici/undici:12285:48)
    at get _request (srvx/dist/adapters/node.mjs:357:21)
    at desc.value [as arrayBuffer] (srvx/dist/_chunks/_url.mjs:22:16)

At that moment request.signal.aborted is still false (the abort fires from the res close handler a beat later).

Why it matters: callers cannot distinguish "client hung up" from "malformed request". Idiomatic proxy code (if (request.signal.aborted || err.name === 'AbortError') return 499) falls through to a 5xx branch and logs an error for every cancelled request.

Suggested fix: in get _request, guard the body handoff — if the body stream is already disturbed/locked or the underlying req is destroyed or errored, construct the native Request with a null body and let signal carry the abort, or surface the abort reason as an AbortError instead of letting undici's extractBody invariant leak.

Caveat: not yet minimized outside our app; it reproduces reliably under h2 with a mid-flight NGHTTP2_CANCEL (client aborts a POST ~20 ms in while the handler reads the body), and we could not trigger it with a synthetic h1 harness.

Activity

  1. added a commit that references this issue on Sep 5, 2026
    3a5187e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions