Skip to content

fix(libSceNet): inherit nonblocking mode on accepted sockets - #4898

Closed
Lorkydey wants to merge 2 commits into
boykopovar:mainfrom
Lorkydey:fix/scenet-accept-nonblocking
Closed

Lorkydey wants to merge 2 commits into
boykopovar:mainfrom
Lorkydey:fix/scenet-accept-nonblocking

Conversation

@Lorkydey

@Lorkydey Lorkydey commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

sceNetAccept now preserves the listener's non-blocking mode in both the accepted host socket and the state returned by sceNetGetsockopt(SO_NBIO).

On the base of this PR, bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684, a connection accepted from a non-blocking listener reports SO_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 with sceNetAccept 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_accept4 with ACCEPT4_INHERIT. PS5 hardware behavior has not been measured; that limitation is recorded in the library's technical debt.

This addresses the separate sceNetAccept path explicitly left outside #3938. The libkernel accept change 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 sceNetEpoll and 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-accept EAGAIN, 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 main bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684.

  • Windows 11 Pro 26100, WinLibs GCC 15.2.0 r7, Ninja, Release: full libs, relinker and targeted test executables build. Local ANYPS5_ENABLE_SPIRV_TOOLS=OFF.
  • guest_sce_net passes 100 consecutive runs, including IPv4 and IPv6. The exact updated head after fix(libkernel_sys): reach rename through a _nid_no_patch export #5025 passes all eight focused tests (guest_sce_net, guest_tcp, guest_udp, four guest_datagram_* cases and patched_libraries) five times each. The initial local 100-run stability check was on preceding head 62df1d73f with identical readiness/network code; the new public Windows job repeats and passes all 100 on final head b2243e14a.
  • The extended test against main's libSceNet/Export.cpp still fails at sceNetAccept did not inherit listener nonblocking mode; restoring this PR passes. The readiness wait therefore does not hide the original regression.
  • The earlier Windows patched_libraries failure was the unrelated libkernel_sys/rename import regression. fix(libkernel_sys): reach rename through a _nid_no_patch export #5025 is now merged into this baseline; the full build and all eight local tests pass without an overlay or exclusion.
  • Public validation: Windows and Linux on the exact updated head passes. Both jobs build runtime/relinker, pass all eight tests five times, verify the inheritance negative control and pass conventions/registration. Windows also passes 100 consecutive runs of the readiness regression. The previous run passed Linux, while Windows reached the known load failure now fixed by fix(libkernel_sys): reach rename through a _nid_no_patch export #5025.
  • Local conventions, test registration and whitespace pass on the updated head.
  • This is focused validation, not the full suite or a title run. No compatibility-percentage increase is claimed.

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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes (Codex)

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test of this PR: the new check in guest_sce_net fails intermittently.

Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON, -j2, libusb-cmake from a local checkout. Built from main c2565f014 with only this PR merged (no conflict).

Result: guest_sce_net aborted in 5 of 25 runs (instrumented copy) and in 3 of 12 runs (unmodified test); on plain main c2565f014 it passed 12 of 12. In the instrumented runs every failure is at Require(accepted[i] >= 0); in CheckAcceptedNonblocking (line 137 of GuestSceNet.cpp on this branch): sceNetAccept on the non-blocking listener (the i == 1 case) returns an error right after sceNetConnect returned 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 EAGAIN before 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).

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Follow-up on the intermittent guest_sce_net abort (Windows 10, MinGW GCC 15.2, -j2).
With only this PR merged onto main c2565f014, guest_sce_net aborted in 3 of 12 runs; every failure of an instrumented copy was at Require(accepted[i] >= 0) in CheckAcceptedNonblocking, the sceNetAccept that follows sceNetConnect on the non-blocking listener. main alone passed 12 of 12.
A separate probe on main db3d379c8 (400 iterations of: non-blocking listener, blocking sceNetConnect, immediate sceNetAccept; 46 runs evaluated, 18 400 attempts): 16 418 accepted at once, 1 982 (10.8 %) returned EAGAIN and succeeded on a retry, 0 other failures. So an immediate non-blocking accept after connect can return EAGAIN on Windows loopback without this PR; the check as written does not retry.
A wait for readability or a retry on EAGAIN before the accept would make the check deterministic (untested).
AI-assisted (Claude Code).

@Lorkydey
Lorkydey force-pushed the fix/scenet-accept-nonblocking branch from b5ce981 to 62df1d7 Compare October 13, 2026 09:29
@Lorkydey
Lorkydey force-pushed the fix/scenet-accept-nonblocking branch from 62df1d7 to b2243e1 Compare October 13, 2026 09:50
@coltken95

Copy link
Copy Markdown

Linux validation (Ubuntu 24.04, GCC 13.3, Release), this PR's commits on main at 77b9f72: guest_sce_net runs CheckAcceptedNonblocking(2) and every check before the IPv6 ones, all passing; the host has no IPv6 loopback, so the IPv6 cases (including CheckAcceptedNonblocking(28)) are skipped and the test exits 77. With main's sources and this PR's test it aborts in the IPv4 accept check.

AI-assisted: yes

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants