fix(libkernel): fail a send during a TCP connect with ENOTCONN on Linux, as FreeBSD 11.4 does #24939
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24939"
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 Dr-Coconut on 2026-11-21T11:47:54Z.
What
FreeBSD 11.4's
sosend_genericfails a send without an address on a stream socket that is not connected withENOTCONN, and a socket whoseconnectis still in progress is not connected. On Linux the guest's send went to the host instead, which waits for the handshake on a blocking socket or fails withEAGAINon a non-blocking one, a gap the libkernel debt file records.connectmarks the socket pending (connectPending, Linux only). The mark stays when the host reportsEINPROGRESS,EALREADYorEINTR, and clears when the connect succeeds or fails otherwise.SendBeforeConnect, whichsend,sendtowithout an address andwritealready consult before waiting, answersENOTCONNwhile the pending socket is not writable (a zero-timeoutpollforPOLLOUT). Once the host reports it writable, whether the handshake completed or failed, the mark clears and sends go to the host as before.GuestTcp.cppgets a Linux-only case: a loopback listener withlisten(fd, 0)holds one connection, so the next non-blockingconnectstays in progress (checked withgetpeername), andsend,writeandsendtowithout an address on it fail withENOTCONN. The debt fragment rewrites the entry without the Linux gap.Tested
Commit
eb76321b73onmainc52d532062, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/44900233617ubuntu-latest, image ubuntu-26.04, GCC 15.2.0), with the change:guest_tcp,guest_udp,guest_socket_pairandguest_kernel_socket_dontwaitpass.Udp.cpprestored tomainand the new case kept:guest_tcpaborts after 0.18 s, in the new case, which runs first; the other three pass.windows-latest, WinLibs GCC 15.2.015.2.0posix-14.0.0-ucrt-r7), with the change: all four pass. The change does not alter Windows.Not run on macOS. No title tested.
tools/check_conventions.pypasses, andtools/debt_fold.py --checkaccepts the fragment (onmainit currently stops atfeat-libwebrtc-rnn-vad.md, which matches no libwebrtc entry).tools/pr_overlap.py --branchmerged 26 open pull requests that share files with this branch and reported #12688, #12700 and #12965, which rework the same lines ofconnect(blocking connects over non-blocking host sockets on Windows) without tracking a pending connect, so they overlap textually. It could not compare three that conflict withmain; compared by hand, #8605 changesGuestSockets::Stat, #11896 reworks the receives, and #18190 movesconnect's body intoconnect_nid_no_patchbehind a wrapper, which keeps these lines.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 MarcZX10 on 2026-11-21T12:20:51Z.
Review: COMMENTED
Reviewed — comments
The change tracks Linux stream connects still in progress and returns
ENOTCONNfor sends while the host socket is not writable; I found one edge case in the readiness check.What I ran
Reviewed head
eb76321b732ccdc8b4a611cf7667c1cf52499d50. No commands or tests were run in this review; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/Socket/src/Udp.cpp:1026:SendBeforeConnecttreats every nonzero result from the zero-timeoutpollas writable, including-1on an interrupted or failed poll. That clearsconnectPendingand lets the send reach the host, contrary to the stated behavior that sends stay blocked until the pending connect completes or fails. Consider clearing the mark only whenpollreturns positive and the returned events indicate completion; retry or preserve pending state on errors.Not verified
core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/tests/GuestTcp.cpp, anddocs/dev/debt/changes/fix-libkernel-send-during-connect.md.files.jsonwas not available through the reader; no additional excluded-file list was verified.To get this to a good state
Nothing is required. The poll-error case is optional feedback.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T12:24:38Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
eb76321b73:tools/check_conventions.pypassed.guest_tcp_testsbuilt cleanly.guest_tcp):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me