Repository navigation
Conversation
php_network_connect_socket() switches the socket to non-blocking mode for the connect and restores the original mode afterwards for synchronous connects. On Windows, SET_SOCKET_BLOCKING_MODE() sets `save = TRUE` and FIONBIO does not write back the previous mode, so RESTORE_SOCKET_BLOCKING_MODE() set the socket to non-blocking again. Winsock cannot query a socket's blocking mode, but all callers pass freshly created (blocking) sockets, so restore to blocking. This matches the POSIX behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #24173.
php_network_connect_socket()switches the socket to non-blocking mode for the connect, and for a synchronous connect it is supposed to restore the original mode afterwards. On Windows,SET_SOCKET_BLOCKING_MODE()setssave = TRUE, andFIONBIOdoesn't write back the previous mode. SoRESTORE_SOCKET_BLOCKING_MODE()passedTRUEagain, and the socket stayed non-blocking while the stream reportedblocked => true. Paths that callrecv()without polling first, such asstream_socket_recvfrom()andsocket_import_stream()+socket_read(), then failed immediately withWSAEWOULDBLOCK.Winsock can't query a socket's blocking mode. However, all callers of
php_network_connect_socket()pass freshly created sockets, which are blocking:php_network_connect_socket_to_host(), the Unix socket connect inxp_socket.c, andphp_connect_nonb()in ext/ftp. So this restores to blocking, which matches the POSIX behavior. Async connects don't callRESTORE, so they are unaffected.The test is Windows-only. It sets a 100 ms
SO_RCVTIMEOon the imported socket and reads with no data available. A blocking socket times out withSOCKET_ETIMEDOUT; a non-blocking one fails at once withSOCKET_EWOULDBLOCK. On Windows, the test fails without the fix and passes with it.Also tested on Windows 11 with a minimal NTS x64 build:
stream_set_timeout()+fread()still times out as expected.stream_set_blocking($c, false)+fread()still returns immediately.This is independent of #24172 (GH-24171), which touches the same function.
🤖 Generated with Claude Code