Fix/windows socket peek waitall (Windows Socket Regression: Test 19/52) #981
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!981
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/981/head"
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?
@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 mergingWindows MSG_PEEK | MSG_WAITALL investigation
Summary
Kyty was passing the guest
MSG_PEEK | MSG_WAITALLflags directly to Winsock.Windows documents that this combination is unsupported and returns
WSAEOPNOTSUPP(10045). Kyty now emulates the combined behavior for WindowsTCP sockets with a per-socket receive buffer. The focused
kernel_file_system_tests.exetest 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, andleave it available for the guest's next receive.
Environment
e317465kernel_file_system_testsBaseline
Command:
Result:
Exit status:
Diagnostic instrumentation
Added logging around the first receive call:
Interpretation:
Winsock error 10045 is
WSAEOPNOTSUPP. Guest errno 45 isEOPNOTSUPP. The returned bytes are all zero, so the host call failed beforecopying payload data. The failing call used guest flags
0x42:The failure was specifically the combined
MSG_PEEK | MSG_WAITALLcall, notMSG_WAITALLby itself. Microsoft documents that Winsock rejects thiscombination with
WSAEOPNOTSUPP:https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv
The process exit status
0xC0000409came from the test's deliberate abortafter 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.
WAITALLalone andPEEKalone 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 individualchecks.
Result:
Conclusion:
Windows rejected the combined flags before receiving any bytes.
Experiment 2: characterize individual flags and split TCP delivery
Change:
Expanded
CheckSocketWakeup()to testWAITALLalone,PEEKalone,PEEK | WAITALL, and payloads sent in two pieces. Added diagnostic output foreach receive.
Result on Windows:
The hex bytes
77 61 6b 65 00arewakefollowed by its NUL terminator.For the split
PEEKtest, onlywahad been sent when the receive ran, sothe two-byte result is expected. A later
WAITALLstill received the fullpayload, confirming that
PEEKleft the first two bytes queued.Conclusion:
Blocking Winsock supports
WAITALLon the tested TCP socket.PEEKworks onits 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-socketbuffer 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.
selectandepollalso treat buffered bytes as readable, because Winsock'sown 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.exepassed with the results listed in Experiment 2.Conclusion:
Kyty now provides the tested
PEEK | WAITALLTCP behavior on Windows whilepreserving the bytes for the next receive.
Full-suite check
Ran the configured CTest suite serially:
The socket test
kernel_file_systempassed. Other failures were environmentlimitations on this laptop: some emulator tests could not reserve the 13.5 GiB
guest memory backing, Vulkan tests reported
vkCreateDevice returned ErrorExtensionNotPresent, andcontroller_settings_tests.exewas not present in the build directory. Thefull 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.
@coderabbitai[bot] on GitHub · 2026-10-02 19:22 UTC · original · edited 2026-10-02 19:45 UTC
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
e4acc675ccand2c59de5469.📒 Files selected for processing (2)
src/libs/network.cpptests/KernelFileSystemTests.cpp🚧 Files skipped from review as they are similar to previous changes (2)
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.
Recvfromuses the buffer for peek and wait-all reads, andEpollWaitandSelectreport buffered data as readable. Tests cover receive flags, split TCP delivery, buffered data after peeking, and zero-timeoutSelectwhile another thread blocks inRecv.Priority: ⬇️ Low
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
2c59dThe 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
e4accA 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
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 helpto get the list of available commands.@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
e317465d8aande4acc675cc.📒 Files selected for processing (2)
src/libs/network.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -2242,0 +2280,4 @@return 0;}#if defined(_WIN32)std::unique_lock receive_lock(transport->receive_mutex);@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_mutexbefore each blocking host receive.On Windows,
Recvfromlocksreceive_lockat Line 2282 and holds it until the function returns. Three paths keep the lock across a call that can block:PEEK | WAITALLloop, which can wait indefinitely in::recv.::recvcalls.::recv/::recvfromat Lines 2374-2382. With an empty buffer, every blocking receive takes this path.HasBufferedReceiveDatalocks the same mutex.SelectandEpollWaitcallHasBufferedReceiveDatabefore their hostselect. Consider this case: one guest thread is blocked inrecv, and another thread callsSelectorEpollWaiton 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:
buffered_receive. Call::recvinto a temporary buffer while the lock is released, then lock again to merge the data.receive_lockso 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.HasBufferedReceiveDatamust not wait on any lock that a blocked receiver holds.✅ Addressed in commit
2c59de5@usopp-sama on GitHub · 2026-10-02 19:22 UTC · original
AI assistance disclosure
I used AI assistance during this change for:
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.
@Nmzik on GitHub · 2026-10-03 17:17 UTC · original
Credited
Pull request closed