fix(net): keep MSG_DONTWAIT transfers nonblocking on Windows #8653
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8653"
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 Ondra97 on 2026-10-20T20:05:08Z.
What
On Windows, the readiness check before a
MSG_DONTWAITreceive could succeed in several threads, then one reader consumed the available byte and another entered a blocking Winsock receive. The regression reproduces this forsceNetRecv,sceNetRecvfromandsceNetRecvmsgon TCP loopback.Native Net sockets now stay non-blocking. Transfers return immediately for
MSG_DONTWAITor guestSO_NBIO; ordinary operations retry after readiness until their existing timeout. Blocking stream sends advance through short host writes until the whole buffer is queued. A timeout or host error after progress returns the queued count; a send timeout without progress returnsEAGAIN. The original deadline is shared across all partial writes. Blocking connect and accept keep their waiting behavior. Readiness waits retry at most every 10 ms so local shutdown is observed even when Winsock does not wakeWSAPoll.The existing native-socket owner carries an optional provider transfer callback. SSL uses it for Net sockets, retaining the socket's lifetime, current guest mode and timeouts without changing the lookup signature or the SSL session constructor. Kernel sockets retain their existing direct native transport.
The blocking stream completion follows FreeBSD 11.4 sosend_generic. The per-call contract follows FreeBSD recv(2); Winsock documents the socket-wide mode in ioctlsocket. This addresses a host defect identified in the PRAGMATA audit in #8005; it does not establish a game blocker or fix that whole issue.
Tested
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 UCRT r7, Release,
BUILD_TESTING=ON. AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER; GPU unused.Main base:
5b59fbc5539b6c6db7a26972f6069f1c6cc179ac. Tested code head:c415375041b70c7ea4c127b0b8016892903c7b91. Documentation-only follow-up:401dee24b6dbfc4d3da865dac59c15ab9d2762af; onlydocs/dev/debt/libSceNet.mdchanged after validation. Runtime and test sources are identical.The initial comparison used base
2185dbf92e8d9013a1620d2dfc95de50494e19f8and original headf29c50766892775df90c689031975e3f432f35f4. The same eight syntheticnet_dontwait_*cases have 4 failures on the base and 0 after the fix: the three competing-reader cases and the pending receive after local close fail on the base. Each reader case runs 32 races with eight readers competing for one byte. Send/sendto/sendmsg and duplex controls also check delivered bytes and unchanged guest blocking flags. A full send is permitted when Winsock accepts the entire buffer.Three new
net_dontwait_blocking_send,_sendtoand_sendmsgtests send a patterned 4 MiB payload to a real loopback reader that drains slowly and verifies every byte. On Windows, test-only wrappers limit each real hostsend/sendtoto 16 KiB to make short writes deterministic. Linux uses the native calls without this limit. Small Winsock buffers alone did not reliably force short writes on this host. The same tests also check a partial count at the original send deadline,EAGAINwithout progress, preserved progress on local abort, and a single host result for guestSO_NBIO.The baseline is the original PR head
f29c507668composed with main5b59fbc553, using the same new test source. Each API returns only 16 KiB there; all three tests fail. After the fix, each returns and delivers the full 4 MiB. These are correctness results with controlled host chunk sizes, not a throughput benchmark.ca55e46f98ad85861dd7567abad0c028274daca1, applied temporarily. Without it, the unchanged main fileImageArrayWindowPastLayerLimit.cppfails atalignas(65536)because WinLibs supports at most 8192 for a static object. The file's baseline blob is0d29ae08e46e33c1cd0e931f951befcf42961ec5. The dependency file was restored byte-for-byte and is absent from this PR. The full build is therefore validation with that dependency, not a passing standalone build without it.net_dontwait_*cases, existing Net/NetCtl/UDP/descriptor/option/select/guest-buffer tests, both SSL transport providers and patched-library loading (354 libraries, zero load failures).guest_pollstill aborts on this host in its urgent-TCP priority wait atGuestPoll.cpp:202. I reproduced the same assertion with the original mainSocketPoll.hppandUdp.cpp, using the same test source and host; both runs fail after the outside peer sendsMSG_OOB. A temporary source-location diagnostic identified line 204 with its two added includes (original line 202), and every diagnostic file was restored. The test remains enabled and unchanged. This is a reproduced baseline failure, not a passing test or a demonstrated regression of this change; the complete suite command below exits with status 8 because of it.guest_poll. The independent run in the comments passedguest_pollon another Windows host; I do not count that as a pass for this updated head.python tools/check_conventions.py --base origin/main,python tools/check_test_registration.py ../buildandgit diff --checkpass.python tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch codex/fix-net-dontwaitreports an adjacent debt-text conflict with #8598, so I list it first in the merge order. The epoll and transfer implementations are independent. I manually inspected the shared-file patches the checker could not compare in #5021, #5836, #6044, #6879, #6977, #7088, #7201 and #8204; none implements this transport fix. #8541 and #8431 touch separate SSL paths.Reproduction commands (with the supported toolchain on
PATH):No game or original console module was run. Console ordering between competing operations remains unmeasured, and the existing Windows stream-receive timeout error mapping remains documented debt. The 10 ms readiness polling interval is also recorded in the library debt.
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 github-actions[bot] on 2026-10-20T20:26:17Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libSceNet/CMakeLists.txtcore/libs/prx/libSceNet/Export.cppdocs/dev/debt/libSceNet.mdcore/libs/prx/libSceNet/CMakeLists.txtcore/libs/prx/libSceNet/Export.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libSceNet/Export.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libSceNet/Export.cppdocs/dev/debt/libSceNet.mdcore/libs/prx/libSceNet/Export.cppcore/libs/prx/libkernel/Socket/src/Udp.cppImported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-20T21:57:02Z.
Independent Windows run of this PR.
Environment: Windows 11 10.0.26300 (same build as the PR description), Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON. I built only
net_dontwait_testsandguest_poll_tests, so the #8310 workaround was not needed.Results:
net_dontwait_*tests pass.libSceNet/Export.cpp,libSceSsl/Export.cpp,libkernel/Socket/include/SocketPoll.hpp,libkernel/Socket/src/Udp.cpp).net_dontwait_recv,_recvfrom,_recvmsgand_blockingfail, and the other four pass. This matches the 4-failure count and the cases named in the description. I restored the PR's files afterwards.guest_poll: the description reports an abort atGuestPoll.cpp:202, reproduced on main. On the PR head it passes here (0.37 s) on this OS build, so that abort looks specific to the author's host.Not run: other platforms, the SSL provider tests, the full repository CTest, and any title or console run.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:30:13Z.
@Ondra97 Thanks. The race is real, the per-call
MSG_DONTWAITcontract is right, and keeping connect and accept blocking keeps the change contained.One request, about blocking sends now that the native socket is always non-blocking. In
native_transfer, any result other than-1/WSAEWOULDBLOCKis returned at once. A non-blocking Winsocksendmay accept fewer bytes than requested ("the number of bytes sent can be less than the number requested", per thesenddocs). So a blockingsceNetSend/sceNetSendto/sceNetSendmsgon a stream socket can now return a short count wheremain's blocking Winsock socket waited. FreeBSD'ssosendblocks a blocking stream send until the whole buffer is queued, and returns short only on a timeout, a signal or an error. Code written for that (onesendof a whole message, with the count checked only for< 0) would silently lose the tail.Could the blocking stream path (no
MSG_DONTWAIT,SO_NBIOoff) keep sending the rest after readiness until it's all queued, the send timeout expires (then return what was sent, orEAGAINif nothing was), or an error occurs? A test would show it: a blockingsceNetSendof a few MiB to a reader that drains slowly, with the full length returned. The currentCheckSendusesMSG_DONTWAIT, where a short count is correct.A smaller point, not a blocker: every thread blocked in a receive now wakes every 10 ms to notice a local close. A one-line debt note about the polling interval would help whoever looks at idle CPU later.
After that, the bar is a full CI run with the
net_dontwait_*tests,guest_polland the existing libSceNet/libSceSsl tests passing on Linux and Windows.Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-21T00:02:38Z.
@oneandonlydean I fixed the blocking stream path in c415375041. It advances through short host writes with one deadline for the whole call, returns queued bytes on timeout or error, and returns
EAGAINwhen the send times out without progress.MSG_DONTWAIT, guestSO_NBIOand datagram sends keep their single-transfer behavior. I also added the debt note about the 10 ms readiness polling interval.The three new send/sendto/sendmsg tests use a real TCP loopback reader and a 4 MiB patterned payload. Test-only Windows wrappers cap each actual host send at 16 KiB, since small socket buffers alone did not reliably force a short write here. The original-head/current-main composition returns only 16 KiB in all three cases; the fix returns and delivers all 4 MiB. Timeout with and without progress, local abort, and guest nonblocking mode also pass. All 11
net_dontwait_*cases pass.The full Windows build completes with the already-declared #8310 test-only dependency, restored afterwards. The focused suite is 54/55 with no skips, including both SSL transport providers;
guest_pollstill fails on this host in the previously documented urgent-TCP case reproduced on main. I have kept that test enabled and documented the failure. This still needs the full Linux and Windows CI run you requested; I am not claiming that bar has passed locally.