fix(libkernel): report a socket shut for reading in poll and select and wake their waiters #11223
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11223"
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 Ragbie on 2026-10-25T22:07:12Z.
What
Follow-up to #10767 for
pollandselect. On Windows, a guest socket whose receive side is shut does not look readable to them, and a thread already waiting is not woken:pollreports nothing aftershutdown(SHUT_RD)andselectleaves the socket out of the read set. Winsock'sWSAPollreports nothing afterSD_RECEIVE.pollreportsPOLLHUP | POLLERRwithoutPOLLIN, because Winsock resets the loopback connection.pollwhen another thread shuts the socket sleeps until its timeout, or forever with-1. Aselectwaiter notices only at its next internal slice.shutdown(SHUT_RDWR),pollreportsPOLLIN | POLLOUTwithoutPOLLHUP.FreeBSD 11.4
pollscanalso clearsPOLLOUTwhenever it reportsPOLLHUP, which #9512 already does on Linux.FreeBSD 11.4
sopoll_genericadds the requestedPOLLIN | POLLRDNORMonce the receive side isSBS_CANTRCVMORE, andPOLLHUPwhen the send side isSBS_CANTSENDMOREtoo.selectusessoreadable, which includes that state.sorflush→socantrcvmore→sorwakeupwakes every poller of the socket, whichever descriptor it polls through.The change, in
core/libs/prx/libkernel/Socket/src/Udp.cpp:pollreports a guest socket whose receive side is shut as readable for the requestedPOLLIN/POLLRDNORM. It addsPOLLHUP, and dropsPOLLOUT, when both sides are shut. Such a socket makes the call return at once.GuestSockets::Poll, whichselectuses for kernel sockets, reports the same socket as readable.shutdownwakes the waiters of every descriptor that refers to the socket (dup,dup2,F_DUPFD).pollwaits only for the time left, and polls again when only the waker fired.SHUT_RDentry notes the extraPOLLHUP | POLLERRthe Windows reset produces, and #9512'spoll on a stream socketentry now covers the Windows both-shut case and FreeBSD'spollrescan, which keepsPOLLOUTfor a socket that hangs up during the wait.Tested
Windows 11, WinLibs GCC 15.2.0, and Linux (Ubuntu 24.04 container, GCC 13.3.0), on
main6cc5ec671with #10767's commits below this PR's two:Rebased onto
main73f4f7e06without conflicts. On this head, on Windows,guest_poll,guest_select,guest_kqueueandguest_select_waitpass with--repeat until-fail:5, and the 157 tests matchingsocket|tcp|udp|kqueue|equeue|guest_net|select|poll|net_|recv|send|shutdown(without the 12select_tests_*tests of the test-selection tool, which the pattern also matches) with--repeat until-fail:3. On Linux the same four pass with--repeat until-fail:5and the 117 matching tests with--repeat until-fail:3. Earlier, onmainc547deaac, the only rebase conflict was the wait condition inpoll_nid_postfix, where #9509 added the macOS urgent-data check; both conditions are kept, and outside macOS that check is always false. The results below are from the earlier base6cc5ec671.guest_poll: readability afterSHUT_RDwith and without queued bytes; a waiter woken within the file's usual bounds (at least 40 ms, under 4 s, 5 s timeout) through the descriptor itself and through adupof it;SHUT_RDWRgives exactlyPOLLIN | POLLHUP.guest_select: readability afterSHUT_RD, and a waiter. With select's own slices this case cannot tell the waker from the next slice; thepollwaiter does.Without the fix,
guest_pollandguest_selectfail on Windows and pass on Linux, where the host already reports and wakes. With it,guest_poll,guest_select,guest_kqueueandguest_select_waitpass with--repeat until-fail:5, and the tests matchingsocket|tcp|udp|kqueue|equeue|guest_net|select|poll|net_pass with--repeat until-fail:3(116 on Windows, 78 on Linux).Windows full build and
ctest:99% tests passed, 5 tests failed out of 2394.agc_write_tracking_metadata_commit,agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_storeandagc_driver_image_plane_address_on_linefail onmainon this machine too, and so doesguest_wide_formatting(%Zgives the host's non-ASCII zone name here; #10981 and #10987 address it).check_skips.py: all skips expected.Linux full
ctest:99% tests passed, 24 tests failed out of 2296; the same 24 fail onmainin this container (22agc_*on its lavapipe and kernel withoutUFFD_FEATURE_WP_ASYNC,pr_overlap_encodingandguest_system_load_exec_standard_error).macOS: not tested.
Not covered here: a thread already blocked in a host
recvon Windows is not released bySHUT_RDfrom another thread, where FreeBSD'ssorflushwakes it and the receive returns 0. That changes the blocking receive path and goes in its own pull request.Overlaps: #7090 adds entries next to this PR's in
docs/dev/debt/libkernel.md; since #10767 merged that is the only conflicting file. Neither needs the other: whichever lands second resolves it and keeps both entries.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 MarcZX10 on 2026-10-25T22:18:19Z.
Review: APPROVED
Reviewed exact head
649a0d231dee80ad6792617ca5fa1353a5a73b3b. I found no actionable issue in the shutdown state propagation or poll/select/kqueue waiter wakeups, including duplicated socket descriptors. Localgit diff --checkandtools/check_conventions.pypass against currentmain. The PR reports focused Windows and Linux test runs; the hosted checks currently cover conventions, intake and labels only, with product builds skipped by repository policy. I did not run a local product build in this relinker-only workspace.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T06:42:57Z.
Review: DISMISSED
Re-reviewed the updated exact head
e36c33c82503fe956b889187e1c10bbe71b0d663. The shutdown handling and duplicated-descriptor wakeup changes have substantial Windows/Linux regression evidence in the latest report; I did not rerun a product build locally. One merge-order blocker remains: the exact merge preview with open #7090 conflicts incore/libs/prx/libkernel/Socket/src/Udp.cppanddocs/dev/debt/libkernel.md; #7090 implements UnixSCM_RIGHTSinrecvmsg, while this PR also changes that receive path and the same debt file. The preview with open #11006 conflicts indocs/dev/debt/libkernel.md. Please coordinate with both authors on which branch lands first, preserve both changes, and declare any required prerequisite on the checklistDepends online. The existingDepends on: #10767and #11141’s reverse dependency do not capture these two overlaps. Current hosted checks do not run product builds for this path; the independent report is local evidence.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T10:13:44Z.
Review: DISMISSED
Re-reviewed exact head
92efd5c137e1b32c6a7c1cd5215207cf2949eeb4against currentmainf99d7fece3.The #7090 overlap is resolved: both authors agreed that whichever PR lands second preserves both
recvmsgchanges, and the current merge preview is clean. I am no longer treating that as a blocker.One integration check remains. The PR's latest reported Windows/Linux runs are on
e36c33c82merged with0f34ebb85, before this head's rebase toc547deaac. Currentmainhas since changedUdp.cpp's poll collection andGuestPoll.cpp's peer-closed-stream expectations (including Apple-specific handling). The exact merge preview with currentmainis clean, but I have not run the product tests locally. Please report the focusedguest_poll,guest_select, and waiter/socket tests on this head integrated with currentmain, including Linux and Windows results; include macOS only if available. Once that evidence is available, I can clear the remaining integration concern.Local checks: current-main merge preview clean;
git diff --checkpasses. Hosted Windows passes; Linux and specialized product jobs are skipped by policy. No local product build or CTest run was performed.