Repository navigation
fix(ext/node): drain all ready connections in poll_tcp_handle to prevent accept starvation - #32943
Merged
Merged
Conversation
…ent accept starvation Previously, poll_tcp_handle accepted only one connection per call, then fired the JS callback. Under high concurrency with mixed node:net and Deno-native I/O, tokio's reactor only re-polls epoll when the event loop returns Pending. Connections that arrived in the same epoll batch were invisible until the next reactor turn, but Phase 2 (pending ops from Deno.listenTls/connect) kept the loop busy, delaying Phase 4 (I/O) and creating a feedback loop where accept throughput degraded to zero. The fix drains all ready connections from poll_accept in a loop before firing callbacks. Each accepted stream goes into internal_backlog, then the connection callback fires once per entry (matching libuv semantics). If the callback doesn't call uv_accept (backlog doesn't shrink), we stop to avoid spinning. Closes #32941 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes node:net accept starvation in uv_compat under high concurrency by changing poll_tcp_handle to drain all ready accepts in one poll and then invoke the connection callback once per accepted stream (with a guard to stop if the callback doesn’t consume the backlog).
Changes:
- Update
poll_tcp_handleto batch/drainpoll_acceptresults into an internal backlog before invoking callbacks. - Invoke the connection callback once per backlog entry, stopping when the backlog no longer shrinks (ie.
uv_acceptwasn’t called). - Add a regression test asserting multiple pre-tick connections are accepted in a single tick.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| libs/core/uv_compat/tcp.rs | Batch-accept loop and per-connection callback firing logic to avoid accept starvation. |
| libs/core/uv_compat/tests.rs | New regression test for batch-accept behavior under multiple pending connections. |
- Fix use-after-free: heap-allocate accepted client handles so they survive until uv_close processes them in the close phase - Set any_work = true when connection callbacks consume backlog entries, ensuring run_io() correctly reports work for pre-existing backlogs - Rename test to tcp_batch_accept (sequential connects, not concurrent) - Fix clippy: use MaybeUninit::uninit() instead of zeroed().assume_init() to avoid UB from zeroing NonNull fields in uv_tcp_t Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
littledivy
approved these changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
node:netaccept starvation under high concurrency when mixed with Deno-native APIs (Deno.listenTls(),Deno.connect())poll_tcp_handlenow drains all ready connections frompoll_acceptin a loop before firing callbacks, instead of accepting only one at a timeuv_acceptRoot cause
Under high concurrent load,
poll_tcp_handlepreviously accepted one connection, fired the JS callback, and moved on. The callback's async work (e.g.,Deno.listenTls) created pending tokio ops processed in Phase 2 of the event loop, delaying the next Phase 4 (I/O) iteration. Since tokio's reactor only re-polls epoll when the event loop returnsPending, connections that arrived in the same epoll batch were invisible until the next reactor turn — creating a feedback loop where accept throughput degraded to zero.Closes #32941
Test plan
tcp_batch_accept_concurrent— opens 8 concurrent connections before ticking the event loop, verifies all 8 are accepted in a single tickuv_compattests pass (58 existing + 1 new)./x fmtand./x lintpass🤖 Generated with Claude Code