fix(libkernel): clear fstat read bits on a socket after the peer closes #8605
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8605"
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 ebarr24 on 2026-10-20T18:11:52Z.
What
fstat on a guest socket kept the read permission bits after the peer shut down its send side, closed or reset the connection, because only this process's own receive shutdown was consulted. FreeBSD 11.4's soo_stat reports no read bits once socantrcvmore is set and the receive buffer is empty. Stat now also asks the host for the peer's end of stream and clears the bits when nothing is queued, so they stay while data is still readable. https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_socket.c
Tested
Windows 11, MinGW-w64 GCC 15.2, Release build with tests.
guest_socket_pairpasses with this change; the new test fails onmain.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 xXPBSXx on 2026-10-20T22:27:11Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
main339217ebc9is clean. I built onlyguest_socket_pair_tests;ctest -N -R socket_pairlists exactly one test.Results (3 runs each):
guest_socket_pairpasses 3/3.core/libs/prx/libkernel/Socket/src/Udp.cppwith itsmainversion, then rebuilt. The test fails 3/3 (exit 0xc0000409, a failedRequire). I restored the PR'sUdp.cppafterwards.Not run: other platforms, the other socket tests, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T09:45:21Z.
Linux data point for
064990ba6e: WSL2 Ubuntu 24.04 (a virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain; its merge-base is73b6a4cc7).ctest -R '^(guest_socket_pair|guest_recvmsg_memory)$'passes 3 of 3 (both tests).core/libs/prx/libkernel/Socket/src/Udp.cpprestored to the merge-base (new test kept):guest_socket_pairfails (Subprocess aborted);guest_recvmsg_memorystill passes.Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:39:07Z.
Review: COMMENTED
Checked against main
522e32e3b6and FreeBSD 11.4 sys/kern/sys_socket.c (soo_stat), sys/kern/uipc_usrreq.c (unp_disconnect), sys/kern/uipc_socket.c (soisdisconnected):docs/dev/debt/libkernel.mdconflicts with main, which has since rewritten the poll entry next to the fstat line and added a Windows "poll … peer closed" entry. The code files merge cleanly, and main'sStat(Udp.cpp:866-899) still has the old rule, so the fix itself is still needed.7701a9b9da), andReady()now has an__APPLE__branch (Udp.cpp:930-936) that peeks withrecv(MSG_PEEK)instead of usingPOLLRDHUP, which is a Linux extension. The new#elsebranch inStatusesPOLLRDHUPdirectly, so it probably needs the same split. I couldn't build on macOS to confirm, and CI doesn't build libkernel there.unp_disconnectcallssoisdisconnectedon both ends (uipc_usrreq.c:1548-1552), which also setsSBS_CANTSENDMORE. So afterclose(pair[0]), FreeBSD reportspair[1]as 0140000, while this reports 0140222. Your third test case only checks the read bits, so it passes either way. The entry could name a peer close as well as a reset for the write bits.soo_stat(sys_socket.c:302-304), and the SHUT_WR case in the new test matchesuipc_shutdown/unp_shutdown.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T10:34:04Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. The code matches the description on read, but I ran no checks and the Linux path has no test, so this is a comment, not an approval.
What I ran
633b9a5bae221cc859363135daf69e00e91c4c3b(basemain)repo_read.py:Results
Findings
Blocking
None.
Non-blocking
docs/dev/debt/libkernel.md:272— "where FreeBSD's socantsendmore also follows a peer reset" is hard to parse. The code clears write bits only fromsendShut(Udp.cpp:1057), so a plainer sentence would say: write bits clear only on this process's shutdown, also on a peer reset.Sources
Not verified
Udp.cpp:1046-1047,POLLRDHUP): the PR's tests were run on Windows only. I read that the Linux branch matches the existingPOLLRDHUPuse atUdp.cpp:1105, but I did not run it.GuestSocketPair.cpp:249-250): relies on an unconnected socket not reporting a peer close on either platform. Checked by reading only.Udp.cpp,GuestSocketPair.cpp,docs/dev/debt/libkernel.md. Excluded by rule: none.To get this to a good state
Nothing is required.
Optional:
libkernel.mdsentence noted above.guest_socket_pairon Linux so thePOLLRDHUPbranch is covered.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T18:11:08Z.
Review: COMMENTED
The new
Statbranch referencesPOLLRDHUPon every non-Windows host. Apple'spoll.hdoes not define it, so this prevents libkernel from compiling on macOS. The existing read-event function in the same file already has a macOS branch that checks stream EOF afterPOLLIN. CanStatuse the same platform distinction? Apple's poll headerSource review at
633b9a5bae. A native macOS build remains unverified.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.