fix(libSceNet): model the guest listen queue past its backlog on macOS #22623
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22623"
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 011010 on 2026-11-17T23:26:25Z.
What
guest_sce_netfails on macOS inCheckConnectTimeoutExpiry:The case creates a listener with
sceNetListen(listener, 0)and connects until one stays pending, because the console stops completing them once the queue is full. macOS does not bound alisten(0)queue at one: 64 connects to such a listener complete without any accept, measured with a host socket.The console depth is not a measurement guess. FreeBSD 11.4 derives it:
solisten_protokeeps the backlog asso_qlimit(uipc_socket.c:747-749), andsonewconndrops a connection onceso_qlen > 3 * so_qlimit / 2(uipc_socket.c:570). A backlog of 0 completes one connection and drops every later one while none is accepted.Each guest listener now counts its completed but unaccepted connections.
sceNetListenstores the backlog,sceNetAcceptreleases one, and a blockingsceNetConnectwith a connect timeout to a guest listener past3 * backlog / 2follows FreeBSD's drop: the host still completes the connection into its own unbounded queue, the guest waits the timeout and getsEAGAIN, and the expired-connect retry keeps returningEADDRINUSE. Everything is under__APPLE__; Linux and Windows build and behave as before.The debt fragment records the bounds: a non-blocking connect past the bound, a connection from outside the guest socket set (which fills the host queue without the count), a negative backlog clamped to FreeBSD's default
somaxconn128, and the count resetting when the listener closes.Tested
main286ee48fb9(which already has #22442, so the connect-refusal case passes and the test reaches this one).connect timeout expiry: no connect stayed pending after 64 completed connects, thencheck failed at line 1212, sceNet errno 61.guest_sce_netpasses end to end, 2.20 s. The expiry case finds its pending connect on the second attempt, the expired retry returns0x80410123after at least the 100 ms timeout, and the follow-up retry returnsEADDRINUSE(48) and then throws.listen(0)completes 64 of 64 connects with none refused.guest_socket_pair,guest_tcp,guest_udpandguest_net_ctlpass.guest_socket_optionsfails with the same message with and without this change (a connect after a refused nonblocking one must fail with ECONNREFUSED (61), not start another attempt (errno 56)), the non-blocking gap the debt entry names.python3 tools/check_conventions.py --base origin/main: all conventions checks passed.python3 tools/pr_overlap.py --names GuestLoopbackSocketand--names NoteGuestListenerConnect: not declared onmainand on no open pull request.python3 tools/pr_overlap.py --branch fix/macos-guest-listen-queue: the same five open pull requests sharelibSceNet/Export.cpp, the libkernel cancellation series; none of them editssceNetConnect,sceNetListenorsceNetAccept.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-11-17T23:30:06Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: ensure a failed
sceNetAcceptsetup does not leave the guest pending-accept count out of sync with the host queue.What I ran
29ab20ffe7b95c1cd9f78ec0a73ac145457a920f; base ismain.review/description.md,review/commits.md,review/manifest.json,review/diff.patch, and the full text of both changed files. No commands or tests were run.Results
Findings
Blocking
core/libs/prx/libSceNet/Export.cpp:1530: The listener'spendingAcceptscount is decremented immediately after the hostacceptsucceeds, before reserving a guest descriptor and before copying the peer address to guest memory. If either later step fails, the accepted socket is closed or discarded, but the host connection has already left the accept queue and the guest count has been released. Subsequent connects can therefore be treated as below the guest backlog limit while the host queue still has no corresponding guest-accepted connection, breaking the modeled queue behavior. Decrement only once the accept operation is successfully committed, or restore the count on every post-accept failure.Non-blocking
Not verified
files.jsonis not available in the prepared review folder.To get this to a good state
pendingAcceptsconsistent when descriptor reservation or guest address copying fails; then rerun the relevantguest_sce_netchecks.Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-18T10:04:23Z.
Review: COMMENTED
Tested on a second Apple M4 (MacBook Air, macOS 27.0.1), x86-64 Release under Rosetta 2,
mainbdc1343e5fwith #17425 and #11049 (needed for the macOS build), head29ab20ffe7.ctest -R '^guest_sce_net$' --output-on-failure, 3 runs each:mainEvery
mainrun reportsconnect timeout expiry: no connect stayed pending after 64 completed connects (last result 0x0, threw 0, 0 ms); the third one then hung until the ctest timeout. With this PR the test passes end to end in every run.AI-assisted: yes (Claude Code)