Skip to content

Accept one connection at a time on a Windows listener, so a paused one delivers in arrival order (#305) - #307

Merged
EdmondDantes merged 1 commit into
mainfrom
listen-single-accept
Sep 30, 2026
Merged

EdmondDantes merged 1 commit into
mainfrom
listen-single-accept

Conversation

@EdmondDantes

Copy link
Copy Markdown
Contributor

Follow-up to #306. libuv keeps completed AcceptEx requests in a LIFO stack (win/tcp.c pushes at :1234, pops at :738). A paused listener that holds several delivers the newest first; #306 switched to single accept at the first stop(), but libuv finishes that switch only after all 32 pre-posted requests are consumed, so every pause until then could reorder. On the server's Windows CI (PR true-async/server#360) h1/064 failed this way: a keep-alive connection overtook an older one, which waited past its 5 s.

Now uv_tcp_simultaneous_accepts(h, 0) is set before the first uv_listen of every Windows TCP listener, and stop() no longer switches. A paused listener holds at most one connection; the rest wait in the kernel backlog in arrival order, and worker threads sharing one socket get an even share (libuv's docs name uneven load as the cost of simultaneous accepts). Cost: one accept per loop iteration on Windows, not measured. Ruling by the Sage over three options (a php-async FIFO queue was rejected: more code, and it keeps up to 32 accepted connections per paused worker).

Evidence: the server's Windows CI on #360 builds this branch through a temporary PHP_ASYNC_BRANCH; h1/064 there is the proof. Linux: a no-op, asynctest 5 of 5.

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@EdmondDantes
EdmondDantes merged commit 2b9981c into main Sep 30, 2026
9 checks passed
@EdmondDantes
EdmondDantes deleted the listen-single-accept branch September 30, 2026 14:39
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