fix(libkernel): return ENOTCONN from getpeername once a socketpair peer closed #8344
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8344"
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 Retr0G28 on 2026-10-20T10:44:02Z.
What
getpeernameon asocketpairend kept returning the unnamedAF_UNIXaddress after the other end was closed. On FreeBSD 11, closing an end runsuipc_detach, whoseunp_disconnect(datagram) andunp_drop(stream) clearSS_ISCONNECTEDon the remaining end (sys/kern/uipc_usrreq.c), andkern_getpeernamethen fails withENOTCONN(sys/kern/uipc_syscalls.c).Each pair end now holds a
std::weak_ptrto the other end's socket. The reference expires when the peer's last descriptor is closed,dup'd copies included, andgetpeernamethen fails withENOTCONN(57).shutdownleaves the ends connected, assoshutdowndoes. The getpeername clause is removed from the socketpair entry indocs/dev/debt/libkernel.md, and "like on every guest socket" becomes "as on every guest socket" to keep the entry under the 1000-character limit.guest_socket_pairnow checks:shutdown(SHUT_WR)still reports the unnamed peer;close,getpeernamefails withENOTCONNand leaves the address and length untouched, whilegetsocknamestill succeeds;dup'd copy stays open keeps the pair connected, and closing the copy disconnects it.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, rebased onmain9d6adeb550.guest_socket_pairwithmain'sUdp.cppfails (exit 0xc0000409 from the failedRequire); with this PR it passes.-R "socket|dup|descriptor|fcntl|pipe|poll|select|recvmsg" -E "^agc_": 41 of 41 passed after the rebase onto47fa6eecf;guest_socket_pairpasses again after the rebases onto11f976b27cand9d6adeb550, whose only conflict each time was the socketpair debt entry.main6cd36e6517(head8f66466e75, clean merge): ctest-R "socket|recvmsg|net_dontwait|^guest_poll$", 40 of 40 pass when run serially, includingguest_socket_pairandguest_recvmsg_memory. Withmain'sUdp.cppon that tree,guest_socket_pairfails again (exit 0xc0000409) andguest_recvmsg_memorystill passes.python tools/check_conventions.py --base origin/mainreports no errors. Its one warning is the length of the socketpair debt entry, 1382 characters onmain, which this PR cuts to 1278.c4450bc82on WSL2 Ubuntu 24.04 (GCC 13.3.0):guest_socket_pairandguest_recvmsg_memorypass, andguest_socket_pairfails withmain'sUdp.cpp(comment below). Not run on bare-metal Linux.Overlap:
getpeername, so whichever merges second needs a one-line rebase.inodemember toSocketnext to this PR's member. This PR goes first, and #10621 declaresDepends on: #8344.getpeernamesentence.tools/pr_overlap.pycould not compare some PRs. I checked those diffs by hand: none changesgetpeernameor the socketpair debt entry.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 xXPBSXx on 2026-10-21T08:45:39Z.
Linux data point for
c4450bc82b: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain; its merge-base is6bd02dd91).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 MarcZX10 on 2026-10-23T05:25:36Z.
Review: DISMISSED
I reviewed the peer-lifetime change and its focused tests. Holding only a
weak_ptrto the peer letsdupshare the same socket object while ensuring the peer expires after the last descriptor owner closes;shutdownleaves the object alive, matching the behavior described. The tests cover stream shutdown/close, untouchedgetpeernameoutputs, and a datagram peer retained by a duplicated descriptor. The PR reports a Windows control that fails on main and passes with the fix, plus WSL2 results; I have not rerun the native tests locally.One integration item remains: against current upstream
main16319642a4c84e861188b75583ce853dfbe0a101,tools/check_main_sync.py --base upstream/main --head upstream/pr-8344-currentreports 1 commit ahead / 10 behind (merge base9d6adeb55), with a clean merge. Please merge current main and rerunguest_socket_pairplus the focused socket tests. Preserve the adjacent null-length ordering change from open #7502 inUdp.cpp; that PR changes neighboring lines but has a separate behavior. This request is for branch freshness and integration, not PR volume.