Skip to content

fix(capabilities): copy wasm request bodies before send#182

Open
bengl wants to merge 1 commit into
mainfrom
bengl/fix-detached-http-body
Open

fix(capabilities): copy wasm request bodies before send#182
bengl wants to merge 1 commit into
mainfrom
bengl/fix-detached-http-body

Conversation

@bengl

@bengl bengl commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

What

Copy WASM-backed request bodies into Node-owned memory before passing them to http.request().write().

Why

Node can queue ClientRequest writes before a socket is assigned. If the queued chunk is a Uint8Array view over WebAssembly.Memory, a later memory.grow() detaches that buffer and Node can throw asynchronously from _flushOutput, outside the transport retry path.

This matches the dd-trace-js system-test crash from PR 9139:

TypeError: Cannot perform Construct on a detached ArrayBuffer
    at new Uint8Array (<anonymous>)
    at new FastBuffer (node:internal/buffer:961:5)
    at Function._uint8ArrayToBuffer (node:stream:142:10)
    at _write (node:internal/streams/writable:312:22)
    at ClientRequest._flushOutput (node:_http_outgoing:1152:18)

Verification

  • node --check crates/capabilities/src/http_transport.js
  • node --check test/http_transport.js
  • node --test test/http_transport.js

Node can queue ClientRequest writes before a socket is assigned. Passing a Uint8Array view over wasm memory lets a later memory.grow detach the queued buffer, which can throw from _flushOutput outside the transport retry path.

Copy the request body into Node-owned memory for each attempt before writing it. The head is still parsed from the current wasm memory view and response handling is unchanged.
@bengl
bengl requested review from a team as code owners July 17, 2026 20:09
@github-actions

Copy link
Copy Markdown

Overall package size

Self size: 30.16 MB
Deduped: 30.16 MB
No deduping: 30.16 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------|

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@bengl bengl mentioned this pull request Jul 20, 2026
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.

1 participant