Fix/windows socket peek waitall (Windows Socket Regression: Test 19/52) #981

Closed
github-bot wants to merge 3 commits from gh-pr/981/head into gh-pr/981/base
Owner

@⁠usopp-sama on GitHub · 2026-10-02 19:19 UTC · original
usopp-sama:fix/windows-socket-peek-waitall → main · +351 −21 · 2 files · 3 commits · closed without merging

Windows MSG_PEEK | MSG_WAITALL investigation

Summary

Kyty was passing the guest MSG_PEEK | MSG_WAITALL flags directly to Winsock.
Windows documents that this combination is unsupported and returns
WSAEOPNOTSUPP (10045). Kyty now emulates the combined behavior for Windows
TCP sockets with a per-socket receive buffer. The focused
kernel_file_system_tests.exe test passes.

The intended guest behavior is:

  • WAITALL: wait for the requested amount of data when the connection permits.
  • PEEK: copy available data without consuming it.
  • PEEK | WAITALL: wait for the requested amount, copy it to the guest, and
    leave it available for the guest's next receive.

Environment

  • Branch: fix/windows-socket-peek-waitall
  • Baseline commit: e317465
  • OS: Windows
  • Compiler: clang-cl 23.1.2
  • Build: Release
  • Test: kernel_file_system_tests
  • Focused build target: kernel_file_system_tests
  • Investigation date: 2026-10-03

Baseline

Command:

.\_Build\windows-no-qt\kernel_file_system_tests.exe

Result:

KernelFileSystemTests: failed:
Net receive forwards PEEK and WAITALL without consuming bytes

Exit status:

0xC0000409

Diagnostic instrumentation

Added logging around the first receive call:

flags: guest 0x42
result: -2143223507
guest errno: 45
WSAGetLastError: 10045
returned bytes: 00 00 00 00 00

Interpretation:

Winsock error 10045 is WSAEOPNOTSUPP. Guest errno 45 is
EOPNOTSUPP. The returned bytes are all zero, so the host call failed before
copying payload data. The failing call used guest flags 0x42:

0x02 = MSG_PEEK
0x40 = MSG_WAITALL

The failure was specifically the combined MSG_PEEK | MSG_WAITALL call, not
MSG_WAITALL by itself. Microsoft documents that Winsock rejects this
combination with WSAEOPNOTSUPP:
https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv

The process exit status 0xC0000409 came from the test's deliberate abort
after its assertion failed; it was not evidence of a separate network crash.

Hypothesis

Kyty must emulate the combined guest behavior on Windows instead of forwarding
the unsupported flag pair directly to Winsock. WAITALL alone and PEEK
alone can continue to use the native host flags.

Experiments

Experiment 1: inspect the failing receive

Change:

Added test diagnostics for the receive result, guest errno, returned bytes,
and WSAGetLastError(). Split the original combined assertion into individual
checks.

Result:

[net diagnostic] PEEK|WAITALL: result=-2143223507 guest_errno=45
bytes=00 00 00 00 00 WSAGetLastError=10045

Conclusion:

Windows rejected the combined flags before receiving any bytes.

Experiment 2: characterize individual flags and split TCP delivery

Change:

Expanded CheckSocketWakeup() to test WAITALL alone, PEEK alone,
PEEK | WAITALL, and payloads sent in two pieces. Added diagnostic output for
each receive.

Result on Windows:

WAITALL with all bytes available: result=5 bytes=77 61 6b 65 00
WAITALL with split delivery:       result=5 bytes=77 61 6b 65 00
PEEK alone:                        result=5 bytes=77 61 6b 65 00
PEEK with split delivery:          result=2 bytes=77 61 00 00 00
PEEK|WAITALL:                      result=5 bytes=77 61 6b 65 00
WAITALL after PEEK:                result=5 bytes=77 61 6b 65 00
KernelFileSystemTests: all cases passed

The hex bytes 77 61 6b 65 00 are wake followed by its NUL terminator.
For the split PEEK test, only wa had been sent when the receive ran, so
the two-byte result is expected. A later WAITALL still received the full
payload, confirming that PEEK left the first two bytes queued.

Conclusion:

Blocking Winsock supports WAITALL on the tested TCP socket. PEEK works on
its own and reports the bytes currently available. The combined case now
passes through Kyty's emulation.

Experiment 3: emulate combined behavior on Windows

Change:

For Windows TCP sockets, Recvfrom() now receives data into a per-socket
buffer until the requested length is reached, then copies it to the guest
without removing it from Kyty's buffer. A subsequent ordinary receive reads
and consumes those buffered bytes. The receive mutex protects this buffer.
select and epoll also treat buffered bytes as readable, because Winsock's
own receive queue has already been drained into Kyty's buffer.

Linux continues to use its existing native socket-flag path.

Result:

The focused Windows target rebuilt successfully, and
kernel_file_system_tests.exe passed with the results listed in Experiment 2.

Conclusion:

Kyty now provides the tested PEEK | WAITALL TCP behavior on Windows while
preserving the bytes for the next receive.

Full-suite check

Ran the configured CTest suite serially:

ctest --test-dir _Build/windows-no-qt --output-on-failure -j 1

The socket test kernel_file_system passed. Other failures were environment
limitations on this laptop: some emulator tests could not reserve the 13.5 GiB
guest memory backing, Vulkan tests reported
vkCreateDevice returned ErrorExtensionNotPresent, and
controller_settings_tests.exe was not present in the build directory. The
full suite is therefore not a useful pass/fail signal for this networking
change on this machine.

Changed files

  • src/libs/network.cpp: Windows receive buffering and readiness reporting.
  • tests/KernelFileSystemTests.cpp: flag behavior, split-delivery coverage,
    and receive diagnostics.
**@⁠usopp-sama** on GitHub · 2026-10-02 19:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/981) `usopp-sama:fix/windows-socket-peek-waitall` → `main` · +351 −21 · 2 files · 3 commits · closed without merging # Windows MSG_PEEK | MSG_WAITALL investigation ## Summary Kyty was passing the guest `MSG_PEEK | MSG_WAITALL` flags directly to Winsock. Windows documents that this combination is unsupported and returns `WSAEOPNOTSUPP` (10045). Kyty now emulates the combined behavior for Windows TCP sockets with a per-socket receive buffer. The focused `kernel_file_system_tests.exe` test passes. The intended guest behavior is: - `WAITALL`: wait for the requested amount of data when the connection permits. - `PEEK`: copy available data without consuming it. - `PEEK | WAITALL`: wait for the requested amount, copy it to the guest, and leave it available for the guest's next receive. ## Environment - Branch: fix/windows-socket-peek-waitall - Baseline commit: e317465 - OS: Windows - Compiler: clang-cl 23.1.2 - Build: Release - Test: kernel_file_system_tests - Focused build target: `kernel_file_system_tests` - Investigation date: 2026-10-03 ## Baseline Command: .\_Build\windows-no-qt\kernel_file_system_tests.exe Result: KernelFileSystemTests: failed: Net receive forwards PEEK and WAITALL without consuming bytes Exit status: 0xC0000409 ## Diagnostic instrumentation Added logging around the first receive call: flags: guest 0x42 result: -2143223507 guest errno: 45 WSAGetLastError: 10045 returned bytes: 00 00 00 00 00 Interpretation: Winsock error 10045 is `WSAEOPNOTSUPP`. Guest errno 45 is `EOPNOTSUPP`. The returned bytes are all zero, so the host call failed before copying payload data. The failing call used guest flags `0x42`: ```text 0x02 = MSG_PEEK 0x40 = MSG_WAITALL ``` The failure was specifically the combined `MSG_PEEK | MSG_WAITALL` call, not `MSG_WAITALL` by itself. Microsoft documents that Winsock rejects this combination with `WSAEOPNOTSUPP`: <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv> The process exit status `0xC0000409` came from the test's deliberate abort after its assertion failed; it was not evidence of a separate network crash. ## Hypothesis Kyty must emulate the combined guest behavior on Windows instead of forwarding the unsupported flag pair directly to Winsock. `WAITALL` alone and `PEEK` alone can continue to use the native host flags. ## Experiments ### Experiment 1: inspect the failing receive Change: Added test diagnostics for the receive result, guest errno, returned bytes, and `WSAGetLastError()`. Split the original combined assertion into individual checks. Result: ```text [net diagnostic] PEEK|WAITALL: result=-2143223507 guest_errno=45 bytes=00 00 00 00 00 WSAGetLastError=10045 ``` Conclusion: Windows rejected the combined flags before receiving any bytes. ### Experiment 2: characterize individual flags and split TCP delivery Change: Expanded `CheckSocketWakeup()` to test `WAITALL` alone, `PEEK` alone, `PEEK | WAITALL`, and payloads sent in two pieces. Added diagnostic output for each receive. Result on Windows: ```text WAITALL with all bytes available: result=5 bytes=77 61 6b 65 00 WAITALL with split delivery: result=5 bytes=77 61 6b 65 00 PEEK alone: result=5 bytes=77 61 6b 65 00 PEEK with split delivery: result=2 bytes=77 61 00 00 00 PEEK|WAITALL: result=5 bytes=77 61 6b 65 00 WAITALL after PEEK: result=5 bytes=77 61 6b 65 00 KernelFileSystemTests: all cases passed ``` The hex bytes `77 61 6b 65 00` are `wake` followed by its NUL terminator. For the split `PEEK` test, only `wa` had been sent when the receive ran, so the two-byte result is expected. A later `WAITALL` still received the full payload, confirming that `PEEK` left the first two bytes queued. Conclusion: Blocking Winsock supports `WAITALL` on the tested TCP socket. `PEEK` works on its own and reports the bytes currently available. The combined case now passes through Kyty's emulation. ### Experiment 3: emulate combined behavior on Windows Change: For Windows TCP sockets, `Recvfrom()` now receives data into a per-socket buffer until the requested length is reached, then copies it to the guest without removing it from Kyty's buffer. A subsequent ordinary receive reads and consumes those buffered bytes. The receive mutex protects this buffer. `select` and `epoll` also treat buffered bytes as readable, because Winsock's own receive queue has already been drained into Kyty's buffer. Linux continues to use its existing native socket-flag path. Result: The focused Windows target rebuilt successfully, and `kernel_file_system_tests.exe` passed with the results listed in Experiment 2. Conclusion: Kyty now provides the tested `PEEK | WAITALL` TCP behavior on Windows while preserving the bytes for the next receive. ## Full-suite check Ran the configured CTest suite serially: ```powershell ctest --test-dir _Build/windows-no-qt --output-on-failure -j 1 ``` The socket test `kernel_file_system` passed. Other failures were environment limitations on this laptop: some emulator tests could not reserve the 13.5 GiB guest memory backing, Vulkan tests reported `vkCreateDevice returned ErrorExtensionNotPresent`, and `controller_settings_tests.exe` was not present in the build directory. The full suite is therefore not a useful pass/fail signal for this networking change on this machine. ## Changed files - `src/libs/network.cpp`: Windows receive buffering and readiness reporting. - `tests/KernelFileSystemTests.cpp`: flag behavior, split-delivery coverage, and receive diagnostics.
Add detailed receive diagnostics and split the combined PEEK|WAITALL assertion into individual checks.

Observed on Windows:
[net diagnostic] PEEK|WAITALL: result=-2143223507 guest_errno=45
bytes=00 00 00 00 00 WSAGetLastError=10045

Inference: Winsock rejects the forwarded PEEK|WAITALL operation with WSAEOPNOTSUPP before receiving any payload, so Kyty needs a Windows compatibility path rather than direct flag forwarding.
Winsock rejects MSG_PEEK combined with MSG_WAITALL on TCP sockets. The diagnostic run returned result=-2143223507, guest_errno=45, and WSAGetLastError=10045 with no payload copied. Emulate the guest behavior with a per-socket receive buffer, and report buffered bytes through select and epoll.

The focused Windows test passes WAITALL, PEEK, split delivery, combined PEEK|WAITALL, and the subsequent consuming receive. Inference: this failure is a host API incompatibility, so Kyty must translate the semantics instead of forwarding the unsupported flag pair.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:39:10 +00:00
github-bot closed this pull request 2026-11-26 09:39:10 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 19:22 UTC · original · edited 2026-10-02 19:45 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: ef558e89-e584-4093-b12d-dab5d0a9f72f

📥 Commits

Reviewing files that changed from the base of the PR and between e4acc675cc and 2c59de5469.

📒 Files selected for processing (2)
  • src/libs/network.cpp
  • tests/KernelFileSystemTests.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/KernelFileSystemTests.cpp
  • src/libs/network.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

On Windows, socket transports now share a mutex-protected receive buffer. Recvfrom uses the buffer for peek and wait-all reads, and EpollWait and Select report buffered data as readable. Tests cover receive flags, split TCP delivery, buffered data after peeking, and zero-timeout Select while another thread blocks in Recv.

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 2c59d

The inspected Windows receive and polling paths show no outstanding issue that should prevent merging after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to e4acc

A connected peer that stops sending can now delay socket polling beyond its timeout, keep a closed connection active, or stall a peek despite available data. These availability risks depend on application use of blocking sockets and are contained to affected networking activity within the running process.

Retained concerns

  • Medium · security · inferred: Readiness deadlines no longer contain a stalled receive. Windows Recvfrom holds receive_mutex across blocking recv or recvfrom, including ordinary receives with no buffered bytes. Select and EpollWait synchronously acquire that mutex before their timed host wait. A peer withholding data from a concurrent receiver can therefore stall even zero-timeout polling and delay events for unrelated sockets in the same polling call.
  • Medium · security · inferred: An active Windows receive now retains the shared SocketTransport. SocketClose removes the guest descriptor but skips native closure while other transport references exist. Consequently, closing a socket with a stalled receive can return success while its connection, receive thread and retained bytes remain live until host I/O terminates. The reference-counted close rule predates the focused change, but retaining ownership throughout Recvfrom newly exposes ordinary blocked receives to it. Explicit Shutdown before close provides a recovery path; close alone does not.
  • Medium · security · inferred: After a successful combined PEEK and WAITALL leaves bytes in the receive buffer, a larger PEEK without WAITALL copies that prefix and then performs a blocking host recv for the remainder. If the host queue is empty and the peer keeps the connection open, the peek stalls even though readiness reports buffered data. This newly weakens the available-data read contract and allows peer-controlled delivery timing to stall callers following a readiness notification.
Security review details

Security Blast Radius

  • inferred — The new blocking synchronization affects Windows non-P2P native receives, not only the stream-only combined-peek emulation. A peer needs an existing guest socket and application behavior that initiates a blocking receive; no elevated privilege is required. If another thread polls that socket alongside others, the same stalled connection can delay the entire polling call. Broader tenant or deployment exposure is not established.

Security Findings and Attack Paths

  • inferred — A connected peer can leave a blocking receive unfinished by withholding data. The receiver retains both the receive mutex and transport ownership. A concurrent readiness call then waits outside its deadline, while guest close detaches the descriptor without necessarily ending the native receive. This is a source-supported availability concern; exploitation was not dynamically demonstrated.

Trust Boundaries and Controls

  • observed — Existing descriptor and unsupported-flag checks remain in the receive route. Buffered bytes belong to a SocketTransport rather than to a reusable descriptor number, and each receive resolves the current mapping. These controls limit direct cross-socket buffer transfer, although they do not make readiness publication or blocked-operation cancellation atomic with close.
  • inferred — Readiness snapshots can outlive descriptor close or reuse, but equivalent fd/native-socket snapshots already existed in the stated baseline. Without evidence of materially increased exposure, that identity race is not treated as a separate introduced concern. A later receive resolves the current transport rather than directly accessing the predecessor's buffered bytes.

Resilience and Maintainability Implications

  • observed — EOF and host errors in combined peeking preserve already buffered bytes; consuming WAITALL returns already copied bytes after a subsequent host error. Explicit Windows Shutdown operates without the receive mutex while the descriptor remains valid, and socket-level nonblocking configuration is available. These are meaningful countermeasures, but callers are not required to use them before polling or close.

Hardening Proposals

  • proposed — Publish buffered readiness without waiting on a mutex held across blocking network I/O, while preserving FIFO receive ownership. For PEEK without WAITALL, return an available buffered prefix promptly rather than waiting for missing host bytes.
  • proposed — Separate safe transport-memory ownership from connection cancellation. An explicit closing state should terminate or wake active native receives before descriptor detachment, while shared references continue to protect in-flight memory access.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Windows socket MSG_PEEK and MSG_WAITALL fix. The regression test reference is additional but relevant.
Description check ✅ Passed The description directly explains the Windows Winsock failure, the buffering implementation, the test coverage, and the reported results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 19:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/981#issuecomment-5959775022) · edited 2026-10-02 19:45 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/981?cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `ef558e89-e584-4093-b12d-dab5d0a9f72f` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e4acc675ccba99f200be1fbedb734baa39e8eaf6 and 2c59de54697165098356541f0e082cfaedfb6a67. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/network.cpp` * `tests/KernelFileSystemTests.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * tests/KernelFileSystemTests.cpp * src/libs/network.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough On Windows, socket transports now share a mutex-protected receive buffer. `Recvfrom` uses the buffer for peek and wait-all reads, and `EpollWait` and `Select` report buffered data as readable. Tests cover receive flags, split TCP delivery, buffered data after peeking, and zero-timeout `Select` while another thread blocks in `Recv`. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"2c59de54697165098356541f0e082cfaedfb6a67" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `2c59d` <!-- final_review_risk_coverage:{"sourceCommitId":"2c59de54697165098356541f0e082cfaedfb6a67","coveredCommitId":"2c59de54697165098356541f0e082cfaedfb6a67","kind":"reviewed"} --> The inspected Windows receive and polling paths show no outstanding issue that should prevent merging after normal checks. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🟡 Moderate_ · up to `e4acc` A connected peer that stops sending can now delay socket polling beyond its timeout, keep a closed connection active, or stall a peek despite available data. These availability risks depend on application use of blocking sockets and are contained to affected networking activity within the running process. **Retained concerns** - **Medium · security · inferred:** Readiness deadlines no longer contain a stalled receive. Windows Recvfrom holds receive_mutex across blocking recv or recvfrom, including ordinary receives with no buffered bytes. Select and EpollWait synchronously acquire that mutex before their timed host wait. A peer withholding data from a concurrent receiver can therefore stall even zero-timeout polling and delay events for unrelated sockets in the same polling call. - **Medium · security · inferred:** An active Windows receive now retains the shared SocketTransport. SocketClose removes the guest descriptor but skips native closure while other transport references exist. Consequently, closing a socket with a stalled receive can return success while its connection, receive thread and retained bytes remain live until host I/O terminates. The reference-counted close rule predates the focused change, but retaining ownership throughout Recvfrom newly exposes ordinary blocked receives to it. Explicit Shutdown before close provides a recovery path; close alone does not. - **Medium · security · inferred:** After a successful combined PEEK and WAITALL leaves bytes in the receive buffer, a larger PEEK without WAITALL copies that prefix and then performs a blocking host recv for the remainder. If the host queue is empty and the peer keeps the connection open, the peek stalls even though readiness reports buffered data. This newly weakens the available-data read contract and allows peer-controlled delivery timing to stall callers following a readiness notification. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The new blocking synchronization affects Windows non-P2P native receives, not only the stream-only combined-peek emulation. A peer needs an existing guest socket and application behavior that initiates a blocking receive; no elevated privilege is required. If another thread polls that socket alongside others, the same stalled connection can delay the entire polling call. Broader tenant or deployment exposure is not established. **Security Findings and Attack Paths** - _inferred_ — A connected peer can leave a blocking receive unfinished by withholding data. The receiver retains both the receive mutex and transport ownership. A concurrent readiness call then waits outside its deadline, while guest close detaches the descriptor without necessarily ending the native receive. This is a source-supported availability concern; exploitation was not dynamically demonstrated. **Trust Boundaries and Controls** - _observed_ — Existing descriptor and unsupported-flag checks remain in the receive route. Buffered bytes belong to a SocketTransport rather than to a reusable descriptor number, and each receive resolves the current mapping. These controls limit direct cross-socket buffer transfer, although they do not make readiness publication or blocked-operation cancellation atomic with close. - _inferred_ — Readiness snapshots can outlive descriptor close or reuse, but equivalent fd/native-socket snapshots already existed in the stated baseline. Without evidence of materially increased exposure, that identity race is not treated as a separate introduced concern. A later receive resolves the current transport rather than directly accessing the predecessor's buffered bytes. **Resilience and Maintainability Implications** - _observed_ — EOF and host errors in combined peeking preserve already buffered bytes; consuming WAITALL returns already copied bytes after a subsequent host error. Explicit Windows Shutdown operates without the receive mutex while the descriptor remains valid, and socket-level nonblocking configuration is available. These are meaningful countermeasures, but callers are not required to use them before polling or close. **Hardening Proposals** - _proposed_ — Publish buffered readiness without waiting on a mutex held across blocking network I/O, while preserving FIFO receive ownership. For PEEK without WAITALL, return an available buffered prefix promptly rather than waiting for missing host bytes. - _proposed_ — Separate safe transport-memory ownership from connection cancellation. An explicit closing state should terminate or wake active native receives before descriptor detachment, while shared references continue to protect in-flight memory access. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the Windows socket MSG_PEEK and MSG_WAITALL fix. The regression test reference is additional but relevant. | | Description check | ✅ Passed | The description directly explains the Windows Winsock failure, the buffering implementation, the test coverage, and the reported results. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts > Autopilot is currently an internal CodeRabbit preview. <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=981)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 19:22 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: f9a52c30-042a-45fe-820e-87a2d83a59dd

📥 Commits

Reviewing files that changed from the base of the PR and between e317465d8a and e4acc675cc.

📒 Files selected for processing (2)
  • src/libs/network.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 19:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/981#pullrequestreview-5395881248) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `f9a52c30-042a-45fe-820e-87a2d83a59dd` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e317465d8a773b33482ad367ad2f856154c8bc6d and e4acc675ccba99f200be1fbedb734baa39e8eaf6. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/network.cpp` * `tests/KernelFileSystemTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -2242,0 +2280,4 @@
return 0;
}
#if defined(_WIN32)
std::unique_lock receive_lock(transport->receive_mutex);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 19:22 UTC · original · edited 2026-10-02 19:43 UTC

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Release receive_mutex before each blocking host receive.

On Windows, Recvfrom locks receive_lock at Line 2282 and holds it until the function returns. Three paths keep the lock across a call that can block:

  • The PEEK | WAITALL loop, which can wait indefinitely in ::recv.
  • The buffered follow-up ::recv calls.
  • The ordinary fall-through ::recv / ::recvfrom at Lines 2374-2382. With an empty buffer, every blocking receive takes this path.

HasBufferedReceiveData locks the same mutex. Select and EpollWait call HasBufferedReceiveData before their host select. Consider this case: one guest thread is blocked in recv, and another thread calls Select or EpollWait on the same socket with a timeout. The second thread then blocks on the mutex until data arrives, and its timeout has no effect. The same can happen with a zero timeout, so a non-blocking poll can hang. A guest that uses a receive thread and a polling or epoll thread can stall.

Do not hold the lock during the host receive. Use one of these fixes:

  • Lock the mutex only to inspect, copy, or append to buffered_receive. Call ::recv into a temporary buffer while the lock is released, then lock again to merge the data.
  • Scope receive_lock so that it is released before the fall-through native receive and before each blocking ::recv. Keep a separate per-transport receive mutex if receives must stay serialized.

HasBufferedReceiveData must not wait on any lock that a blocked receiver holds.

✅ Addressed in commit 2c59de5

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 19:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/981#discussion_r4169054628) · edited 2026-10-02 19:43 UTC _🩺 Stability & Availability_ | _🟠 Major_ | _🏗️ Heavy lift_ **Release `receive_mutex` before each blocking host receive.** On Windows, `Recvfrom` locks `receive_lock` at Line 2282 and holds it until the function returns. Three paths keep the lock across a call that can block: - The `PEEK | WAITALL` loop, which can wait indefinitely in `::recv`. - The buffered follow-up `::recv` calls. - The ordinary fall-through `::recv` / `::recvfrom` at Lines 2374-2382. With an empty buffer, every blocking receive takes this path. `HasBufferedReceiveData` locks the same mutex. `Select` and `EpollWait` call `HasBufferedReceiveData` before their host `select`. Consider this case: one guest thread is blocked in `recv`, and another thread calls `Select` or `EpollWait` on the same socket with a timeout. The second thread then blocks on the mutex until data arrives, and its timeout has no effect. The same can happen with a zero timeout, so a non-blocking poll can hang. A guest that uses a receive thread and a polling or epoll thread can stall. Do not hold the lock during the host receive. Use one of these fixes: - Lock the mutex only to inspect, copy, or append to `buffered_receive`. Call `::recv` into a temporary buffer while the lock is released, then lock again to merge the data. - Scope `receive_lock` so that it is released before the fall-through native receive and before each blocking `::recv`. Keep a separate per-transport receive mutex if receives must stay serialized. `HasBufferedReceiveData` must not wait on any lock that a blocked receiver holds. <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:7401bd34c25dd785abb16a0d --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 2c59de5
Author
Owner

@⁠usopp-sama on GitHub · 2026-10-02 19:22 UTC · original

AI assistance disclosure
I used AI assistance during this change for:

  • Investigation: tracing Kyty’s receive path and interpreting the Winsock error and socket flags.
  • Implementation: developing the Windows compatibility approach for MSG_PEEK | MSG_WAITALL.
  • Testing: adding receive diagnostics and expanding the focused tests for individual flags and split TCP delivery.
  • Documentation: summarizing the findings and test results in my investigation notes.

I reviewed the generated changes, built the focused Windows test target, and ran kernel_file_system_tests.exe; it passed.

Models used: GPT 5.6 Sol (light), GPT 6 Light.

**@⁠usopp-sama** on GitHub · 2026-10-02 19:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/981#issuecomment-5959777815) AI assistance disclosure I used AI assistance during this change for: - Investigation: tracing Kyty’s receive path and interpreting the Winsock error and socket flags. - Implementation: developing the Windows compatibility approach for MSG_PEEK | MSG_WAITALL. - Testing: adding receive diagnostics and expanding the focused tests for individual flags and split TCP delivery. - Documentation: summarizing the findings and test results in my investigation notes. I reviewed the generated changes, built the focused Windows test target, and ran kernel_file_system_tests.exe; it passed. Models used: GPT 5.6 Sol (light), GPT 6 Light.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-03 17:17 UTC · original

Credited

**@⁠Nmzik** on GitHub · 2026-10-03 17:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/981#issuecomment-5971564667) Credited

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.