fix(libSceNet): inherit nonblocking mode on accepted sockets #4898
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4898"
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 Lorkydey on 2026-10-13T02:50:55Z.
What
sceNetAcceptnow preserves the listener's non-blocking mode in both the accepted host socket and the state returned bysceNetGetsockopt(SO_NBIO).On the base of this PR,
bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684, a connection accepted from a non-blocking listener reportsSO_NBIO = 0. On Linux the accepted host socket is also blocking, so an empty receive can wait indefinitely. Windows inherits the host mode but still reports the wrong guest state. The new regression fails on main withsceNetAccept did not inherit listener nonblocking mode.The implementation explicitly enables the inherited host mode before registering the connection and records it on that connection. A host mode-setting failure closes the new socket through the existing owner and returns the translated error. Changing either socket's mode later does not change the other.
This follows FreeBSD 11.4
kern_accept4withACCEPT4_INHERIT. PS5 hardware behavior has not been measured; that limitation is recorded in the library's technical debt.This addresses the separate
sceNetAcceptpath explicitly left outside #3938. The libkernelacceptchange in #3958 does not change this implementation. No title run or compatibility-percentage increase is claimed.Windows readiness follow-up
The test now registers the listener with
sceNetEpolland waits for readable readiness with a one-second timeout before each accept. A completed blocking connect does not itself guarantee that a subsequent nonblocking accept already sees the connection on Windows loopback, as xXPBSXx measured on main. The wait is test synchronization; it introduces no production retry, sleep or fallback. The empty-acceptEAGAIN, inherited mode, independent mode changes and data checks remain.The branch is rebased after #4391, retaining its socket descriptor model. The unverified PS5 hardware behavior is now recorded under Unknown function infos in the debt file.
Tested
Exact source:
b2243e14a60af0df15988b3f8dc394ff022bf930, based on mainbb9a4d8a244cb4cbe3a8c9f69a21074b696e7684.libs,relinkerand targeted test executables build. LocalANYPS5_ENABLE_SPIRV_TOOLS=OFF.guest_sce_netpasses 100 consecutive runs, including IPv4 and IPv6. The exact updated head after #5025 passes all eight focused tests (guest_sce_net,guest_tcp,guest_udp, fourguest_datagram_*cases andpatched_libraries) five times each. The initial local 100-run stability check was on preceding head62df1d73fwith identical readiness/network code; the new public Windows job repeats and passes all 100 on final headb2243e14a.libSceNet/Export.cppstill fails atsceNetAccept did not inherit listener nonblocking mode; restoring this PR passes. The readiness wait therefore does not hide the original regression.patched_librariesfailure was the unrelatedlibkernel_sys/renameimport regression. #5025 is now merged into this baseline; the full build and all eight local tests pass without an overlay or exclusion.Overlap
#4391 is merged and included in the baseline. A pairwise merge with the current #5004 head is clean after placing the hardware uncertainty in the proper debt section; its libc signature cleanup does not implement socket-mode inheritance. #4613 changes address-length reporting, and #3958 handles libkernel
accept, not this implementation.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-13T08:20:39Z.
Windows test of this PR: the new check in
guest_sce_netfails intermittently.Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
BUILD_TESTING=ON,-j2,libusb-cmakefrom a local checkout. Built frommainc2565f014with only this PR merged (no conflict).Result:
guest_sce_netaborted in 5 of 25 runs (instrumented copy) and in 3 of 12 runs (unmodified test); on plainmainc2565f014it passed 12 of 12. In the instrumented runs every failure is atRequire(accepted[i] >= 0);inCheckAcceptedNonblocking(line 137 ofGuestSceNet.cppon this branch):sceNetAccepton the non-blocking listener (thei == 1case) returns an error right aftersceNetConnectreturned 0. It looks like the pending connection is not yet visible to a non-blocking accept on Windows loopback; that is a guess, not measured. The check passes when the accept succeeds.Suggestion (untested): wait until the listener is readable (poll with a timeout) or retry on
EAGAINbefore treating the accept as failed.Not checked: whether the same race exists in the implementation and not only in the test; the PR base is older than #4391, so the interaction with the new descriptor model is also open; Linux not tested; no title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T09:08:46Z.
Follow-up on the intermittent
guest_sce_netabort (Windows 10, MinGW GCC 15.2,-j2).With only this PR merged onto
mainc2565f014,guest_sce_netaborted in 3 of 12 runs; every failure of an instrumented copy was atRequire(accepted[i] >= 0)inCheckAcceptedNonblocking, thesceNetAcceptthat followssceNetConnecton the non-blocking listener.mainalone passed 12 of 12.A separate probe on
maindb3d379c8(400 iterations of: non-blocking listener, blockingsceNetConnect, immediatesceNetAccept; 46 runs evaluated, 18 400 attempts): 16 418 accepted at once, 1 982 (10.8 %) returnedEAGAINand succeeded on a retry, 0 other failures. So an immediate non-blocking accept afterconnectcan returnEAGAINon Windows loopback without this PR; the check as written does not retry.A wait for readability or a retry on
EAGAINbefore the accept would make the check deterministic (untested).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T11:11:44Z.
Linux validation (Ubuntu 24.04, GCC 13.3, Release), this PR's commits on
mainat77b9f7270:guest_sce_netrunsCheckAcceptedNonblocking(2)and every check before the IPv6 ones, all passing; the host has no IPv6 loopback, so the IPv6 cases (includingCheckAcceptedNonblocking(28)) are skipped and the test exits 77. Withmain's sources and this PR's test it aborts in the IPv4 accept check.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:32:58Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed