fix(libkernel): refuse a reconnect after a failed nonblocking connect on Windows #14183
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14183"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-31T22:39:35Z.
What
On Windows, calling
connectagain after a refused nonblocking streamconnectstarted a fresh connection attempt.Each repeat returned
EINPROGRESS(36), whileSO_ERRORheldECONNREFUSED(61). So a title that keeps callingconnectuntil it stops reportingEINPROGRESSorEALREADYnever sees the refusal and keeps retrying the dead server.FreeBSD 11.4's
tcp_usr_connectanswers a socket whose connection was dropped (INP_DROPPED) withECONNREFUSED, whether a reset or a timeout dropped it.Measured on
mainwith a probe inguest_socket_options(nonblocking socket, fourconnectcalls, poll after the second):connect0connect1SO_ERRORmain192.0.2.1:9(attempt still in flight)The in-flight case already returns
EALREADY, because Winsock reportsWSAEALREADYthere. Only the case after a failed attempt was wrong.The fix applies on Windows to stream sockets:
WSAEWOULDBLOCKfromconnectmarks the socket as having a pending attempt.connectreads the hostSO_ERROR. Winsock does not clear it on read, so this does not consume the error the guest reads later throughSO_ERROR.connectand every later one returnECONNREFUSEDwithout calling Winsock again.Linux and macOS are unchanged.
sceNetConnecthad the same gap, so a second commit applies the same rule there:Sockentry remembers a pending connect (WSAEWOULDBLOCKon a guest nonblocking socket, orWSAEALREADY).sceNetConnectreads the hostSO_ERRORbefore it resetsreported_error. Once the attempt has failed, it returns0x80410100 | ECONNREFUSEDfrom then on.The Windows sentence of the "Socket error numbers" entry in
docs/dev/debt/libkernel.mddescribed this wrongly: it said a repeat "keeps reportingEALREADY". It now describes the new behaviour.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, full build with
BUILD_TESTING=ON, onmain7a5d9bf02a.guest_socket_optionsReconnectAfterARefusalFails. It makes a nonblocking connect to a closed loopback port, polls until the attempt settles, and requires the nextconnectto fail withECONNREFUSED.Udp.cpprestored tomain(the control build relinkedlibkernel.prx): fails witha connect after a refused nonblocking one must fail with ECONNREFUSED (61), not start another attempt (errno 36).sceNetConnectinguest_refused_connect: a nonblockingsceNetSocket(SO_NBIO) connects to the closed loopback port. It retries while the answer isEINPROGRESSorEALREADY, for at most 3 s, and must end with0x80410100 | 61and errno 61.libSceNet/Export.cpprestored (the control build relinkedlibSceNet.prx): aborts after the 3 s deadline.ctest -R "socket|refused|udp|tcp|net_|_net|poll|select|connect|http|ssl" -j8 --repeat until-fail:3: 207/207 pass with both commits.connectafter the refusal. As I read Linux's__inet_stream_connect, a socket still marked connecting gets the pending socket error from that call. I have not run it there, and CI will.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T23:13:07Z.
Review: APPROVED
Reviewed — looks good
The Windows-only state tracking preserves a failed nonblocking stream connect and makes a later connect report
ECONNREFUSED; the new tests exercise both guest socket APIs.What I ran
Reviewed head
80c8ea873ee9adfc5f6e9861cc34ada1e0607b25against PR base7a5d9bf02af636382aec927593b1a5867899ed0f; merge preview was clean. Environment: Linux x86_64, Python 3.11.2. No local C++ build or CTest was run.Results
Raw hosted check summary
Negative control
No negative control was run. The regression is timing-dependent and Windows-specific; I relied on the hosted Windows job and the new repeated-connect tests rather than altering the implementation locally.
Sources
Not verified
To get this to a good state
No blocking change is needed based on the reviewed head and available checks. The only outstanding hosted result I saw was the labels check.