streams: close a listening socket at once on Windows - #29
Merged
Conversation
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
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.
Carries #28 over to
true-async-stable. The two branches differ by exactlythose commits, and only in
main/streams/xp_socket.c.php_sockop_closewaits up to 500 ms for the socket to become writable so theOS 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 eventloop instead of
closesocket(). The port stays bound afterfclose()returnsand 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 from508 ms to 0 ms.
This is the branch the Windows job of
true-async/php-asyncbuilds php-srcfrom, so the fix only reaches that CI once this lands.