Skip to content

fix(ext/node): fix child_process.send() backpressure return value - #33869

Merged
bartlomieju merged 4 commits into
mainfrom
fix/child-process-send-backpressure
May 6, 2026
Merged

bartlomieju merged 4 commits into
mainfrom
fix/child-process-send-backpressure

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Summary

  • Fix child_process.send() to return false when more than one message is queued waiting for a handle ACK, matching Node.js behavior
  • Previously used a threshold of 16 (handleQueue.length < 16), now uses handleQueue.length === 1 to signal backpressure after the first queued message

Test plan

  • ./x test-compat test-child-process-send-returns-boolean.js now passes

When a handle send is pending ACK and subsequent messages are queued,
`send()` should return `false` as soon as more than one message is
queued (matching Node.js behavior). Previously, Deno used a threshold
of 16, which caused `send()` to incorrectly return `true` when the
caller should have been signaled to back off.
Uses internal/child_process kChannelHandle with readStop/readStart
which is not exposed in Deno.

@fibibot fibibot 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.

Substance is correct — 1-line backpressure-threshold fix:

- return handleQueue.length < 16;
+ return handleQueue.length === 1;

The walkthrough lines up with Node's lib/internal/child_process.js semantics for send()'s return value:

  • 1st send(msg) while queue is empty → push pushes msg in, queue length is now 1 → returns true (no backpressure, consumer should keep sending).
  • 2nd send(msg2) while msg1 still waits for ACK → queue length is now 2 → returns false (backpressure: caller should pause).

The old < 16 threshold was a holdover that doesn't match Node — Node returns false immediately on the second queued message regardless of an arbitrary threshold. The new === 1 matches.

Test enablement

  • parallel/test-child-process-send-returns-boolean.js: enabled — directly exercises this assertion.
  • parallel/test-child-process-recv-handle.js: added with ignore: true ("Uses internal/child_process kChannelHandle with readStop/readStart which is not exposed in Deno"). Reasonable scope-limit; that test exercises a different surface that this PR doesn't address.

CI

54 success, 12 pending, 0 fail at this HEAD (CI is rebuilding after the merge-main commit 559298c9). The 11 fails I noted on an earlier head must have been a stale CI state — the substantive shards haven't started yet. Will re-confirm once they land. Substance is APPROVE-quality once CI clears.

@fibibot fibibot 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.

LGTM — clearing the APPROVE-pending hold from my prior comment at this same HEAD. CI fully green now: 134 success, 2 skipping, 0 fail across all platforms × debug + release.

What I verified

The 1-line change matches Node's lib/internal/child_process.js semantics for send()'s return value:

- return handleQueue.length < 16;
+ return handleQueue.length === 1;
  • 1st send(msg) while queue is empty → push makes queue length 1 → returns true (no backpressure, consumer should keep sending).
  • 2nd send(msg2) while msg1 still waits for ACK → queue length is 2 → returns false (backpressure: caller should pause).

The old < 16 threshold was a holdover; Node's actual behavior signals backpressure on the second-and-beyond queued message regardless.

Test enablement is right-sized:

  • parallel/test-child-process-send-returns-boolean.js enabled — directly exercises the boolean return value contract.
  • parallel/test-child-process-recv-handle.js added with ignore: true and a clean reason ("Uses internal/child_process kChannelHandle with readStop/readStart which is not exposed in Deno") — separate surface, scope-limited correctly.

CI

134 success, 2 skipping, 0 fail. All 4 platforms × debug + release passed test node_compat, test unit_node, test specs, test integration.

@bartlomieju
bartlomieju merged commit 82588c3 into main May 6, 2026
266 of 270 checks passed
@bartlomieju
bartlomieju deleted the fix/child-process-send-backpressure branch May 6, 2026 18:10
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…noland#33869)

- Fix `child_process.send()` to return `false` when more than one
message is queued waiting for a handle ACK, matching Node.js behavior
- Previously used a threshold of 16 (`handleQueue.length < 16`), now
uses `handleQueue.length === 1` to signal backpressure after the first
queued message
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