Skip to content

streams: close a listening socket at once on Windows - #29

Merged
EdmondDantes merged 2 commits into
true-async-stablefrom
true-async
Aug 25, 2026
Merged

streams: close a listening socket at once on Windows#29
EdmondDantes merged 2 commits into
true-async-stablefrom
true-async

Conversation

@EdmondDantes

Copy link
Copy Markdown

Carries #28 over to true-async-stable. The two branches differ by exactly
those commits, and only in main/streams/xp_socket.c.

php_sockop_close waits up to 500 ms for the socket to become writable so the
OS can flush what is queued. A listening socket has no peer and never becomes
writable, so the wait always runs its full course — and under the async
reactor it creates a poll_event, which routes the descriptor to the event
loop instead of closesocket(). The port stays bound after fclose() returns
and the next bind on it is refused.

Measured on ext/http_server's phpt suite: 107 passed / 53 failed before,
139 passed / 22 failed after; fclose() on a listening socket drops from
508 ms to 0 ms.

This is the branch the Windows job of true-async/php-async builds php-src
from, so the fix only reaches that CI once this lands.

php_sockop_close waits up to 500 ms for the socket to become writable so
the OS can flush what is still queued. A listening socket has no peer and
never reports writability, so the wait always runs its full course — and
under the async reactor it creates a poll event, which hands the
descriptor to the event loop and defers the real closesocket() to a later
turn. The port stays bound after fclose() returns, and the next bind() on
it is refused.

Skip the flush for a socket in the listening state; a connected socket
keeps the wait it needs.
streams: close a listening socket at once on Windows
@EdmondDantes
EdmondDantes requested a review from bukka as a code owner August 25, 2026 05:49
@EdmondDantes
EdmondDantes merged commit 146a711 into true-async-stable Aug 25, 2026
2 checks passed
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