fix(libkernel): fail sends and receives on a socketpair end whose peer closed on Windows #15785
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15785"
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 Dom3005 on 2026-11-04T14:47:18Z.
What
On Windows a guest
socketpairend is a loopback TCP connection or two connected UDP sockets, so the host did not see the peer's close the way FreeBSD does (#15661). Both ends live in this process and the socket table already links them, and on Windows nothing else can own the host socket (noSCM_RIGHTS), so an expired peer link means the peer is closed.sendafter the peer closed fails withEPIPEfrom the first call. Before, the loopback connection accepted one more send and only the ones after it reportedEPIPE. This follows FreeBSD 11.4'sunp_disconnect, which callssoisdisconnectedon both ends.unp_dropsetsso_error = ECONNRESETon the surviving end.soreceive_dgramreturns it once, and only when the queue is empty (queued datagrams still arrive first;MSG_PEEKleaves the error), orsosend_generictakes it on the next send. After that, a send without an address fails withEDESTADDRREQ. The pair's UDP sockets now haveSIO_UDP_CONNRESEToff, as guest UDP sockets already do, so Winsock's port-unreachable resets (which only arrived after a send, and repeated) no longer leak through.This answers #15661 differently from what the issue asks for the datagram case. The issue and the old debt entry say the console returns
ENOTCONN, but that sentence comes from the original socketpair commit (8f31696450) and cites no measurement, and FreeBSD 11.4 givesECONNRESETas described above. The debt entry now cites the FreeBSD source and says the console is unmeasured. It also records what is still missing on Windows:poll,keventandSO_ERRORdon't report the pending error, and a receive that is already blocked when the peer closes keeps waiting.Tested
Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON, onupstream/mainb11c7bf84f.guest_socket_pairandguest_recvmsg_memory: passed 5/5 (ctest --repeat until-fail:5).main'sUdp.cppaborts (0xc0000409) inguest_socket_pair.ctest -R "socket|sock|recv|send|pipe|poll|select|kevent|kqueue|equeue|net|dup|fstat|udp|tcp": 253/253 passed.python tools/check_conventions.py --base upstream/main: 0 errors. The one warning isdebt-lengthon the socketpair entry, which was already 1279 characters onmain.Not tested: Linux and macOS. The code change only takes effect on Windows. The test change that also runs there is the stream case, which now expects
EPIPEon the first two sends after the peer closed, where it used to loop up to 100 times.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-07T15:57:14Z.
Review: CHANGES_REQUESTED
Thanks for the work. #16081 merged yesterday and already covers most of this: a stream
sendafter the peer closed fails withEPIPEfrom the first call, and an empty datagramrecvafter the peer closed fails withECONNRESET(54), both measured on a PS5 (13.60 and 11.60), with the debt entry updated. This PR now conflicts withmaininUdp.cppanddocs/dev/debt/libkernel.md.What is left of the diff is behaviour main does not have, and it rests on reading FreeBSD, not on the console:
ECONNRESET(peerResetTaken,Udp.cpp:133,PendingPeerReset), where main keeps answering 54 on every empty receive. The console measurement only covers the first receive after the close. Please measure a secondrecvand asendon the console; if it differs from main, add that measurement to the PR.EDESTADDRREQ(39) for asendwithout an address after the reset (ClosedPeerSendError,Udp.cpp:919-929), andECONNRESETon the firstsend. Same: unmeasured, and the debt entry says so.SIO_UDP_CONNRESEToff on the pair's UDP sockets (Udp.cpp:1025-1030). Separate fix and independent of the above; fine as its own small PR with a test that fails without it.Please rebase onto current
mainand keep only the parts the console measurements support (a streamEPIPEand the empty-queuerecvare done, so drop the duplicates, including the test and the debt rewrite of those). The debt entry should then add only what remains.Pull request closed