libkernel: MSG_DONTWAIT can block on Windows after a readiness check #10943

Open
opened 2026-10-25 11:15:02 +00:00 by lgqdaxia · 0 comments
lgqdaxia commented 2026-10-25 11:15:02 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by lgqdaxia on 2026-10-25T11:15:02Z.


PS5 console results, November 21, 2026 (firmware 9.20). With plain MSG_DONTWAIT, eight readers competed for one byte. Across eight rounds per socket type, both TCP loopback and local stream sockets returned eight bytes total and 56 EAGAIN results. No reader was still waiting at the 0.5 s check. The separate one-byte MSG_DONTWAIT | MSG_WAITALL cases reached setup and hit the 5 s limit before printing a receive result. An immediate one-byte return for that combination remains unconfirmed on PS5. Console measurements by @noisyweather.

Latest tested standalone candidate: 6adaa5acdf, based on main 88f99678bf, on the candidate branch. It retains the Windows DONTWAIT/progress fixes and @Queuse's authored Unix SSL follow-up, and adds live native-mode handling with independent read/write regressions.

SCM_RIGHTS integration: f54d693980 contains that complete candidate plus #7090 at 484bc8c2c3, on the same main base. Testing found and corrected a retained callback regression that changed a passed nonblocking socket's EAGAIN into a wait.

Windows full builds and 13 selected CTests pass on both pinned versions. Linux actual-source harness results are 6/6 for the standalone candidate and 13/13 for the combined targeted transport suite, including supplementary TCP/TLS-over-passed-socket checks. Four separate passed-option/peer diagnostic checks still fail and remain explicit limitations of the integration stack. Those October results apply to the named Windows builds and Linux harnesses.

Detailed combined results, negative controls, remaining gaps and local TLS driver. The original report below retains its historical revisions and measurements. The diagnostic stack is not a ready upstream PR.

What happens

On Windows, a guest socket call that asks not to wait can still get stuck in a blocking Winsock receive. The readiness check succeeds, but it does not make the following receive nonblocking.

This is a remaining gap explicitly recorded by merged #8186 and the MSG_DONTWAIT debt entry. #8185's unsupported-flag error was fixed; this report concerns the later blocking transfer. The libSceNet changes in #8653 cover a different socket implementation.

Title, test or build step

Synthetic loopback/API regression: guest_socket_dontwait. No title or homebrew was run.

In the original Windows test, one byte is queued on a connected blocking socket, the peer stays open, and recv(buffer, 2, MSG_DONTWAIT | MSG_WAITALL) (0xc0) is called. The old Windows runtime waits until the peer closes. The candidate test expects one byte immediately. That expectation is provisional pending an isolated console result.

A separate contention case starts eight real recv(MSG_DONTWAIT) calls for one queued byte. One may take the byte; the other seven should return EAGAIN. With the old blocking transport, some receivers instead remain pending until peer shutdown. No gate or delay is inserted inside production code.

AnyPS5 commit

  • Tested main: 57f506f8119252b43b851b0de18689bc5015a586, freshly built for this investigation.
  • Candidate: 887d081fe30cab8871b91cc6f6c64b127d99713c, based on that main commit.
  • At publication, main had advanced to 16ff208dc32cf3927ba1bae492eee363a5ae7ae8. Its libkernel/Socket sources, libkernel CMake registration and GuestSslTransport.cpp are unchanged from the tested base. The build/test results below apply to the stated revisions, not a new full run at 16ff208dc3.

System

Windows 11 10.0.26200, Intel Core i7-12700H, WinLibs GCC 15.2.0 r7, Release. These socket/SSL tests do not initialize a GPU.

Steps to reproduce

In a separate Windows checkout at main 57f506f8119252b43b851b0de18689bc5015a586, with the toolchain and dependencies from BUILD, take only the test and its registration:

git fetch https://github.com/lgqdaxia/AnyPS5.git codex/fix-dontwait-socket-race
git restore --source=887d081fe30cab8871b91cc6f6c64b127d99713c --worktree -- core/libs/tests/GuestSocketDontWait.cpp core/libs/prx/libkernel/CMakeLists.txt
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake --build build --target libs guest_socket_dontwait_tests --parallel 4
ctest --test-dir build -R '^guest_socket_dontwait$' -V

Those two restored files add no production fix. The first case reports the failure in about 0.6 seconds, after safely releasing the blocked receiver. It does not depend on a watchdog or CTest timeout to fail.

In another checkout of candidate 887d081fe3, run the same configure, build and CTest commands for the green comparison. The complete regression takes about six seconds here.

Log

Main runtime:

socket DONTWAIT: MSG_DONTWAIT | MSG_WAITALL waited for a second byte despite one available byte
guest_socket_dontwait ... Failed (0.55 sec)

Candidate:

socket DONTWAIT preserves per-call and blocking receive semantics
guest_socket_dontwait ... Passed (5.89 sec)

The final test EXE was also run with a retained copy of the freshly built main runtime and failed at the same assertion (exit 1, about 0.7 seconds). That is the same EXE used with the candidate runtime. The main libkernel SHA-256 is 65f3bcc96ee93046511bd99c3a2059ac5ebdfa3367590296d1f3cbe5596c3b2b; the candidate is 2cc7babed33cf271ae3c4dcb5c7e0c6c8600c635b017ce4a4d64afd7c0e1df86.

What was checked

  • Main: 71 existing focused network/SSL CTests passed before the SSL timeout case was extended; the new socket regression fails as above.
  • Candidate: 72 related CTests passed, including refused connections, UDP/TCP, socket options/timeouts, sendfile, libSceNet DONTWAIT and SSL. The additional guest_socket_dontwait regression passed three consecutive runs.
  • The new regression checks ordinary blocking reads and WAITALL, eight competing readers in 64 rounds for each guest mode, mode changes through fcntl/FIONBIO/SO_NBIO, waiting accept, PEEK data preservation, full-queue sends, peer-drain wakeup and a send timeout after read EOF.
  • The extended SSL kernel timeout case passes with the candidate. In a separate process, clearing only its retained NativeOwner transfer callback makes that read return in 0.001 ms and fail the new minimum-wait assertion. The extended kernel case with the old runtime exceeded a 30-second process limit; it is not part of the main 71-pass claim.
  • Full libs and relinker builds, conventions and public-header audit passed. The header audit first hit CTest's 30-second limit; the direct audit passed, then the unchanged CTest passed in 12.59 seconds.

Proposed fix and status

The public candidate branch keeps exposed Windows native sockets nonblocking. Guest blocking mode is tracked separately: a normal call waits for the required direction and retries against its deadline; a DONTWAIT call returns the native result immediately. The same path covers the SSL NativeOwner callback so ordinary SSL reads still wait and honor guest timeouts.

The wait uses directional select. A separate native probe found that WSAPoll can repeatedly report HUP after a peer half-closes while a full send queue still returns would-block; watching the exception set also wakes on unrelated urgent data. The probe checked that write-only select waits in those cases and still wakes on a reset. The formal test checks the timeout behavior, not CPU usage.

The transport changes and regression are in #12688, which lists Fixes #10943. Its immediate one-byte assertion for the combined flags is subject to the console finding above. Blocking Windows MSG_PEEK | MSG_WAITALL remains unsupported (EOPNOTSUPP) and is recorded in debt. Single large-send probes did not establish backpressure; the regression instead fills the queue with bounded small sends until EAGAIN.

The original reproduction and logs in this section came from local Windows synthetic tests.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6023798935 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10943). Originally posted by [lgqdaxia](https://github.com/lgqdaxia) on 2026-10-25T11:15:02Z. --- **PS5 console results, November 21, 2026 (firmware 9.20).** With plain `MSG_DONTWAIT`, eight readers competed for one byte. Across eight rounds per socket type, both TCP loopback and local stream sockets returned eight bytes total and 56 `EAGAIN` results. No reader was still waiting at the 0.5 s check. The separate one-byte `MSG_DONTWAIT | MSG_WAITALL` cases reached setup and hit the 5 s limit before printing a receive result. An immediate one-byte return for that combination remains unconfirmed on PS5. [Console measurements by @noisyweather](https://github.com/boykopovar/AnyPS5/issues/10943#issuecomment-7074097760). **Latest tested standalone candidate:** [`6adaa5acdf`](https://github.com/lgqdaxia/AnyPS5/commit/6adaa5acdf716f37ecef7b410505f91d8a75b8b0), based on main `88f99678bf`, on [the candidate branch](https://github.com/lgqdaxia/AnyPS5/tree/codex/fix-dontwait-socket-race). It retains the Windows DONTWAIT/progress fixes and @Queuse's authored Unix SSL follow-up, and adds live native-mode handling with independent read/write regressions. **SCM_RIGHTS integration:** [`f54d693980`](https://github.com/lgqdaxia/AnyPS5/commit/f54d69398062ae2e76f4e846cbfce1f78eed6a15) contains that complete candidate plus #7090 at `484bc8c2c3`, on the same main base. Testing found and corrected a retained callback regression that changed a passed nonblocking socket's EAGAIN into a wait. Windows full builds and 13 selected CTests pass on both pinned versions. Linux actual-source harness results are 6/6 for the standalone candidate and 13/13 for the combined targeted transport suite, including supplementary TCP/TLS-over-passed-socket checks. Four separate passed-option/peer diagnostic checks still fail and remain explicit limitations of the integration stack. Those October results apply to the named Windows builds and Linux harnesses. [Detailed combined results, negative controls, remaining gaps and local TLS driver](https://github.com/boykopovar/AnyPS5/issues/10943#issuecomment-6403963410). The original report below retains its historical revisions and measurements. The diagnostic stack is not a ready upstream PR. <!-- lgqdaxia-10943-latest-live-mode-f54d693980 --> ### What happens On Windows, a guest socket call that asks not to wait can still get stuck in a blocking Winsock receive. The readiness check succeeds, but it does not make the following receive nonblocking. This is a remaining gap explicitly recorded by merged #8186 and the [MSG_DONTWAIT debt entry](https://github.com/boykopovar/AnyPS5/blob/57f506f8119252b43b851b0de18689bc5015a586/docs/dev/debt/libkernel.md#L217). #8185's unsupported-flag error was fixed; this report concerns the later blocking transfer. The libSceNet changes in #8653 cover a different socket implementation. ### Title, test or build step Synthetic loopback/API regression: `guest_socket_dontwait`. No title or homebrew was run. In the original Windows test, one byte is queued on a connected blocking socket, the peer stays open, and `recv(buffer, 2, MSG_DONTWAIT | MSG_WAITALL)` (`0xc0`) is called. The old Windows runtime waits until the peer closes. The candidate test expects one byte immediately. That expectation is provisional pending an isolated console result. A separate contention case starts eight real `recv(MSG_DONTWAIT)` calls for one queued byte. One may take the byte; the other seven should return `EAGAIN`. With the old blocking transport, some receivers instead remain pending until peer shutdown. No gate or delay is inserted inside production code. ### AnyPS5 commit - Tested main: [`57f506f8119252b43b851b0de18689bc5015a586`](https://github.com/boykopovar/AnyPS5/commit/57f506f8119252b43b851b0de18689bc5015a586), freshly built for this investigation. - Candidate: [`887d081fe30cab8871b91cc6f6c64b127d99713c`](https://github.com/lgqdaxia/AnyPS5/commit/887d081fe30cab8871b91cc6f6c64b127d99713c), based on that main commit. - At publication, main had advanced to `16ff208dc32cf3927ba1bae492eee363a5ae7ae8`. Its `libkernel/Socket` sources, libkernel CMake registration and `GuestSslTransport.cpp` are unchanged from the tested base. The build/test results below apply to the stated revisions, not a new full run at `16ff208dc3`. ### System Windows 11 10.0.26200, Intel Core i7-12700H, WinLibs GCC 15.2.0 r7, Release. These socket/SSL tests do not initialize a GPU. ### Steps to reproduce In a separate Windows checkout at main `57f506f8119252b43b851b0de18689bc5015a586`, with the toolchain and dependencies from BUILD, take only the test and its registration: ```powershell git fetch https://github.com/lgqdaxia/AnyPS5.git codex/fix-dontwait-socket-race git restore --source=887d081fe30cab8871b91cc6f6c64b127d99713c --worktree -- core/libs/tests/GuestSocketDontWait.cpp core/libs/prx/libkernel/CMakeLists.txt git submodule update --init --recursive cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON cmake --build build --target libs guest_socket_dontwait_tests --parallel 4 ctest --test-dir build -R '^guest_socket_dontwait$' -V ``` Those two restored files add no production fix. The first case reports the failure in about 0.6 seconds, after safely releasing the blocked receiver. It does not depend on a watchdog or CTest timeout to fail. In another checkout of candidate `887d081fe3`, run the same configure, build and CTest commands for the green comparison. The complete regression takes about six seconds here. ### Log Main runtime: ```text socket DONTWAIT: MSG_DONTWAIT | MSG_WAITALL waited for a second byte despite one available byte guest_socket_dontwait ... Failed (0.55 sec) ``` Candidate: ```text socket DONTWAIT preserves per-call and blocking receive semantics guest_socket_dontwait ... Passed (5.89 sec) ``` The final test EXE was also run with a retained copy of the freshly built main runtime and failed at the same assertion (exit 1, about 0.7 seconds). That is the same EXE used with the candidate runtime. The main libkernel SHA-256 is `65f3bcc96ee93046511bd99c3a2059ac5ebdfa3367590296d1f3cbe5596c3b2b`; the candidate is `2cc7babed33cf271ae3c4dcb5c7e0c6c8600c635b017ce4a4d64afd7c0e1df86`. ### What was checked - Main: 71 existing focused network/SSL CTests passed before the SSL timeout case was extended; the new socket regression fails as above. - Candidate: 72 related CTests passed, including refused connections, UDP/TCP, socket options/timeouts, sendfile, libSceNet DONTWAIT and SSL. The additional `guest_socket_dontwait` regression passed three consecutive runs. - The new regression checks ordinary blocking reads and WAITALL, eight competing readers in 64 rounds for each guest mode, mode changes through fcntl/FIONBIO/SO_NBIO, waiting accept, PEEK data preservation, full-queue sends, peer-drain wakeup and a send timeout after read EOF. - The extended SSL kernel timeout case passes with the candidate. In a separate process, clearing only its retained NativeOwner transfer callback makes that read return in 0.001 ms and fail the new minimum-wait assertion. The extended kernel case with the old runtime exceeded a 30-second process limit; it is not part of the main 71-pass claim. - Full `libs` and `relinker` builds, conventions and public-header audit passed. The header audit first hit CTest's 30-second limit; the direct audit passed, then the unchanged CTest passed in 12.59 seconds. ### Proposed fix and status The [public candidate branch](https://github.com/lgqdaxia/AnyPS5/tree/codex/fix-dontwait-socket-race) keeps exposed Windows native sockets nonblocking. Guest blocking mode is tracked separately: a normal call waits for the required direction and retries against its deadline; a DONTWAIT call returns the native result immediately. The same path covers the SSL NativeOwner callback so ordinary SSL reads still wait and honor guest timeouts. The wait uses directional `select`. A separate native probe found that `WSAPoll` can repeatedly report HUP after a peer half-closes while a full send queue still returns would-block; watching the exception set also wakes on unrelated urgent data. The probe checked that write-only select waits in those cases and still wakes on a reset. The formal test checks the timeout behavior, not CPU usage. The transport changes and regression are in #12688, which lists `Fixes #10943`. Its immediate one-byte assertion for the combined flags is subject to the console finding above. Blocking Windows `MSG_PEEK | MSG_WAITALL` remains unsupported (`EOPNOTSUPP`) and is recorded in debt. Single large-send probes did not establish backpressure; the regression instead fills the queue with bounded small sends until `EAGAIN`. The original reproduction and logs in this section came from local Windows synthetic tests. AI-assisted: yes <!-- lgqdaxia-kernel-dontwait-887d081 -->
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#10943
No description provided.