Skip to content

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

Merged
bengl merged 1 commit into
mainfrom
bengl/restore-wasm-body-copy
Aug 31, 2026
Merged

fix(capabilities): copy wasm request bodies before send#225
bengl merged 1 commit into
mainfrom
bengl/restore-wasm-body-copy

Conversation

@bengl

@bengl bengl commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Restores the WASM HTTP transport request-body copy on main. httpRequest now writes a Node-owned Buffer copy of the body for each attempt instead of a live Uint8Array view over wasm memory, adapted to the current signature that carries connectionPooling.

Adds a regression test (http_transport request body lifetime) that grows the wasm memory after httpRequest returns but before Node flushes its queued write.

Motivation

This fix shipped on the v0.x release branch in v0.18.1 (#184, commit 5c2e31d) but was never forward-ported to main, so main regressed to the original behavior. Node can queue ClientRequest writes before a socket is assigned; a later memory.grow() detaches the backing ArrayBuffer and ClientRequest._flushOutput throws asynchronously, outside the req.write() try/catch retry path.

Found while preparing the v0.19.0 release, which takes main onto v0.x — without this, 0.19.0 would reintroduce a bug fixed in 0.18.1.

How to test the change?

In a worktree at this branch:

  • node --test test/http_transport.js — 21 pass, 0 fail
  • same command with the http_transport.js change stashed — 1 fail: TypeError: Cannot perform Construct on a detached ArrayBuffer, from the new test
  • npx eslint . — clean

Not run locally: the root native suite (yarn test), which needs a full cargo prebuild; CI covers it.

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.

This landed on the v0.x release branch in v0.18.1 but was never brought
back to main, so main still writes the live wasm view.

Refs: #184
@bengl
bengl marked this pull request as ready for review August 31, 2026 17:38
@bengl
bengl requested review from a team as code owners August 31, 2026 17:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T17:40:28.710336Z 2e99ff1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gyuheon0h gyuheon0h left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. We should make sure v0.x's history tracks main's history.

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is needed, since it is already in a release and we should sync main and the release branch

@github-actions

Copy link
Copy Markdown

Overall package size

Self size: 31.66 MB
Deduped: 31.66 MB
No deduping: 31.66 MB

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

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

@bengl
bengl merged commit ae6f3bc into main Aug 31, 2026
52 checks passed
@bengl
bengl deleted the bengl/restore-wasm-body-copy branch August 31, 2026 17:45
@bengl bengl mentioned this pull request Aug 31, 2026
bengl added a commit that referenced this pull request Aug 31, 2026
v0.x's copy of the wasm request-body test predates the connectionPooling
parameter, so replaying it here calls httpRequest with the old
nine-argument signature and reads wasm_memory from the wrong slot. Take
main's version, which #225 landed with the extra argument.

Also take main's Cargo.lock and yarn.lock; replaying the dependency
bumps produced only cosmetic dedupe-key differences from the tree those
commits were reviewed against.
bengl added a commit that referenced this pull request Aug 31, 2026
v0.x's copy of the wasm request-body test predates the connectionPooling
parameter, so replaying it here calls httpRequest with the old
nine-argument signature and reads wasm_memory from the wrong slot. Take
main's version, which #225 landed with the extra argument.

Also take main's Cargo.lock and yarn.lock; replaying the dependency
bumps produced only cosmetic dedupe-key differences from the tree those
commits were reviewed against.
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.

3 participants