fix(libkernel): treat a socket direction that is already shut as shut on macOS hosts #9625
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9625"
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 rooklz on 2026-10-22T04:53:15Z.
What
guest_socket_pairfails on macOS hosts atGuestSocketPair.cpp:238: after the peer'sshutdown(SHUT_WR),shutdown(pair[1], SHUT_RD)returns -1 withENOTCONN. A small host program shows the same thing: on a connectedAF_UNIXstream pair,shutdown(b, SHUT_RD)succeeds on a fresh pair, fails withENOTCONN(57) once the peer has shut its sending side, and the 5 queued bytes are still readable afterwards.The two kernels differ here:
soshutdownlock_final(bsd/kern/uipc_socket.c) returnsENOTCONNwhen the direction asked for is already shut (/* read already shut down */,/* write already shut down */), and forSHUT_RDWRit jumps todonebefore the write side when the read side was already shut.soshutdown(sys/kern/uipc_socket.c) returnsENOTCONNonly when the socket isn't connected; for a connected socket it shuts what was asked and returns 0, whatever was shut before.On macOS,
shutdownnow treatsENOTCONNfrom a socket that still has a peer (getpeernamesucceeds) as a direction that was already shut: the call succeeds and the guest's shut state is recorded as before. ForSHUT_RDWRthe write side is then shut explicitly, since XNU skipped it. A socket without a peer still fails withENOTCONN, as on FreeBSD. Linux and Windows behave as before.@iamthehimansh's #8658 and @marion909's #7201 make the same change as part of their macOS ports (#8658 for
SHUT_RDonly). This is that change on its own with the test it fixes, as #8920 did for thefflushguard. Whichever lands first, the other drops these lines.Tested
mainalone, so this ran on @mugurc'sci/macos-series-2at53db0badbwith #7524, the code of #7937 and the libSceSsl change of #7332.guest_socket_pairwithout this change aborts atGuestSocketPair.cpp:238(found with lldb); with it, it passes.guest_socket_pairpasses.ci/macos-series-2at27e968974with this change and six other macOS PRs cherry-picked:guest_socket_pairaborts atGuestSocketPair.cpp:238without it and passes 2 of 2 with it; no test that passed before fails with the batch applied.check_conventions.pypasses.pr_overlap.pyreports the same lines in #8658, as described above.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-22T09:23:51Z.
Review: DISMISSED
The macOS behavior is narrowly scoped: an
ENOTCONNresult is treated as an already-shut direction only whengetpeernameconfirms the socket still has a peer;SHUT_RDWRexplicitly attempts the write shutdown after XNU’s read-side early exit. The reported macOS control (same integration tree without this change fails, with it passes) and Linux test pass are useful, but the hosted product jobs are skipped and I did not rerun runtime tests here. Exact-head conventions and whitespace pass. Please coordinate the sharedUdp.cpphunk with #8658 and #7201 before merge; the description says either port PR must drop these lines if this one lands first, so record the agreed order/dependency in the checklist or thread.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T11:31:07Z.
On the #5239 direction: this came from running the suite on the macOS port tree discussed on #1, where the shutdown tests fail without it, not from a title. I am fine holding it until the queue drops or a maintainer says otherwise, or closing it in favour of #8658 if that is preferred.
Merge order, recorded here: if #8658 or #7201 lands first, I rebase this and drop whatever their
Udp.cpphunk already covers. If this lands first, their hunk at those lines conflicts and the resolution is to keep this version ofshutdown_nid_postfix.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:31:14Z.
Rebased onto current
main(8b3e39832a): head7c213787ac, same diff.check_conventions.pypasses on it.Refreshed results on this head:
guest_socket_pairpasses 3 of 3 on the macOS integration tree (the same tree as in the description, carrying exactly thisUdp.cpp), and a hosted Linux run of the socket tests is at https://github.com/rooklz/AnyPS5/actions/runs/39787396014 (in progress; I'll note the result).Landing order with the two port PRs is now written on both of them, #8658 and #7201: whichever lands first, the other drops its copy of the
shutdown_nid_postfixhunk, and if a port lands first I rebase this onto it. I've asked both authors to say if they'd rather fold it in, in which case I close this.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:59:40Z.
The hosted Linux run on head
7c213787acfinished: the socket tests,guest_socket_pairamong them, pass (https://github.com/rooklz/AnyPS5/actions/runs/39787396014, Ubuntu 24.04, GCC, Release).