fix(libSceNet): accept SO_CONNECTTIMEO and bound blocking connects by it #11571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11571"
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 NevesHenry on 2026-10-26T20:47:15Z.
What
sceNetSetsockoptfailedSOL_SOCKEToption0x1109withEOPNOTSUPP. shadPS4 names itORBIS_NET_SO_CONNECTTIMEO, next to0x1105and0x1106, the send and receive timeouts in microseconds that AnyPS5 already takes.Codex PS5 (PPSA99105) creates a stream socket, sets
0x1105to 1,500,000,0x1106to 100,000 and0x1109to 1,500,000, then connects to its service on127.0.0.1:49322. The third set fails, so the title writes this to its/download0/codex-ps5-network.log, closes the socket and tries again every 500 ms:(
0x8041012disSCE_NET_ERROR_EOPNOTSUPP, errno 45.) It never callssceNetConnect, so it can't reach its service even when the service is running. Retail titles use the option too: Metal Gear Solid 4 (PPSA18194 01.004.003) passes0x1109tosceNetSetsockoptat four call sites (found by @milescoviello, see the comments).Change (
core/libs/prx/libSceNet/Export.cpp):sceNetSetsockoptkeeps the0x1109value per socket, andsceNetGetsockoptreads it back. A negative value fails withEINVAL, as it does for0x1105and0x1106.sceNetConnectwith a timeout set waits at most that long. On Linux and macOS it connects with the host socket made non-blocking, polls for writability for the remaining time, readsSO_ERRORand then makes the socket blocking again. Windows sockets are already non-blocking here, so the existingselectgets the same limit.std::runtime_error, as the other unsupported cases in this file) and has alibSceNettechnical debt entry. shadPS4 returnsEWOULDBLOCKand leaves the attempt running. A timeout of 0, a non-blocking socket and a datagram socket still take the old path.Tested
Linux: Ubuntu 22.04 on WSL2, Ryzen 9 7900, lavapipe, GCC 13, Release.
Title: Codex PS5 - Prototype (PPSA99105) 00.000.004, the
codex-ps5-0.0.4-Folder.ziprelease of Portablelle/Codex-PS5. Its SHA-256 isb6f8952b72eaa4806baab21634aae950f69a365bee4215a373d750e8f652364b, the same as in the darkxex homebrew catalog. I unwrappedeboot.binandsce_module/libc.prx, relinked with--registryand ran it for 30 s per run under Xvfb in a container with no network except loopback. The real service is a separate payload (assistant-service.elf) that needs a jailbroken console, so I didn't run it. Instead, a small TCP listener on127.0.0.1:49322logged whatever it received.maine61a7c7e24connect timeout 8041012d 0000002d, and the listener gets no connection{"id":1,"method":"initialize","params":{"capabilities":{"experimentalApi":true},"clientInfo":{"name":"codex_ps5","title":"Codex PS5","version":"0.0.4"}}}connect timeout 8041012d 0000002dconnect 8041013d 0000003d(ECONNREFUSED)guest_sce_nethas a newCheckConnectTimeout. It checks that:0x1109reads 0 on a new socket, a negative value fails withEINVAL, and 1,500,000 reads back.ECONNREFUSED. The bound socket stays open until the end, so no other process can take the port.It aborts on
mainand passes with this change.CheckConnectTimeoutExpiry(b57df488a, from review) makes a connect run into its timeout.0x1109at 100 ms, until one stays pending because the listener's queue is full.056b076ffd, any number is accepted, including none, up to a cap of 64.std::async, and the test aborts if a connect hasn't returned after 5 s. An ignored timeout therefore fails instead of hanging.std::runtime_erroror a nonzero error result (869ec68d9f, from review), and only after at least 80 ms. A later evidence-based error code therefore keeps the test passing.SO_NBIO0 andSO_ERROR0, and closes.recvon a socket that isn't connected yet fails at once withENOTCONNthere. So that last part doesn't run on Windows.Requireprints its line and the sceNet errno. The expiry loop also prints the completed connects, the last result and the elapsed time.pollwithout the deadline, the old blocking connect for this case, andconnect_withinnot restoring the flags after the expiry.guest_sce_netaborted on869ec68d9fwith no message, 3 times. With the SYNs to the expiry listener dropped by iptables in a private network namespace, I got the same abort locally, at the!queued.empty()check.056b076ffdpasses that case 3/3. Its controls:Export.cppfrom before this PR aborts, at the first0x1109check.poll(..., -1)aborts through the 5 s guard, with the message. ReturningETIMEDOUTin place of the throw passes 3/3. A SYN answered with a reset aborts, withthe pending connect returned before its timeout after 0 completed connects (last result 0x8041013d ...).windows-latest(Windows Server 2025), WinLibs GCC 15.2.0, Release,guest_sce_net_testsbuilt from b57df488a by a throwaway workflow in my fork:guest_sce_netpasses 10/10, with one queued connection and the expiry after 101.1 ms.Merged with
main5cb015caaa(95ff923f89, no conflicts). Linux, Ryzen 9 7900:guest_sce_netpasses 10/10.ctest -R '(net|socket|ssl|http|rudp|epoll|resolver)'passes 142/142 at-j8, and again with-j16 --repeat until-fail:3.guest_sce_net_testspass 48/48. They ran 16 at a time, each in its own directory, with 24 busy loops on the 24 threads.Earlier, merged onto
main737f17291a(clean):ctest -R '(net|socket|ssl|http|rudp|epoll|resolver)'100/100 pass. Fullctestwithout the AGC tests: 1486/1491; the other five arepr_overlap_toolsandcheck_main_sync(git 2.34),guest_runtime_lifecycle(fails on this machine, withmaintoo in earlier runs), andselect_testsandvulkan_validation_gate_attribution, which pass when run again on their own.Full
ctest -j16on the earlier base263eee0a7: 2344/2386 pass. The other 42 are AGC tests that fail on this WSL lavapipe, pluspr_overlap_toolsandcheck_main_sync, which need git 2.38 while this host has 2.34. All 42 fail the same way on amainbuild of the same base.Windows: only
guest_sce_net_testswas built, as above. macOS: not built.tools/check_conventions.py --base origin/mainpasses.Overlap:
tools/pr_overlap.pyneedsgit merge-tree --write-tree, so I checked by hand. I rangit merge-treeagainst the 23 open PRs that changelibSceNet/Export.cpp,GuestSceNet.cppordebt/libSceNet.md. None of them handles0x1109. #11559 and #7490 change other lines ofsceNetConnect, and each merges cleanly with this.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-10-27T00:17:49Z.
Review: DISMISSED
Reviewed exact head
f77ba0525e7a92079f99e3afd506772efb1c5fc7. Changes requested for missing coverage of the primary behavior this PR adds.[P2] Exercise a connect that actually reaches the configured timeout.
CheckConnectTimeoutverifies option readback, a successful loopback connect, receive timeout afterward, and an immediately refused connection. Neither path enters the expiry branch inconnect_within/the Windowsselect, so the test would still pass if the configured deadline were ignored and a stalled connect blocked indefinitely. The reported title run also exercises only an accepting listener and an immediately refused port. Please add a deterministic test for an in-progress connection that remains pending past a short configured timeout, and assert it exits within a bounded interval through the documented unsupported-timeout exception path; then verify the socket's native blocking mode is restored and the still-pending attempt is handled consistently. If a portable deterministic fixture is difficult, inject the connect/poll boundary so the timeout result and elapsed-budget logic can be controlled without relying on external network routing.The test gap is in the core contract (blocking stream
sceNetConnectwaits at most the configured time), not in the console's unknown timeout errno: the PR correctly avoids inventing that errno and records it as technical debt. Hosted eligibility, conventions, labels and report pass; product builds are skipped by path policy. The author reports 88 focused Linux CTests and the title listener repro, but I did not rerun them locally.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T10:48:03Z.
Review: CHANGES_REQUESTED
Thanks, the option handling and the
connect_within/selectbounds look right. One thing blocks this:core/libs/tests/GuestSceNet.cpp:733-764CheckConnectTimeoutnever reaches the expiry branch (connect_withinreturningCONNECT_EXPIRED,core/libs/prx/libSceNet/Export.cpp:1196, and the Windowsselectreturning 0 at:1222). It covers readback, a successful connect and an immediateECONNREFUSED, so it would still pass if the timeout were ignored and a stalled connect blocked forever. This is the main behaviour of the PR, so it needs a test that fails without it (tests must pin values, not just the happy path).Suggested direction: make a connect stay pending deterministically (for example a loopback listener with a tiny backlog already filled, so the SYN is dropped), set
0x1109to a short value such as 100 ms, and assert the call leaves through the documented exception within a bounded time, then that the socket is blocking again. If that is not portable on Windows, put the connect/poll boundary behind a small seam so the timeout logic can be driven without the network.Same request as @MarcZX10's review on this head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:59:59Z.
Review: DISMISSED
Re-checked — changes requested
What I checked
869ec68d9fagainst fetchedmain2960e9a6e7; the merge preview is clean andgit diff --checkpasses.Remaining blockers
CheckConnectTimeoutExpiryonly acceptsstd::runtime_erroras the timeout outcome. The PR records the console timeout error as unknown, so this test should allow either the current unsupported-path exception or a nonzero guest error result; otherwise a later evidence-based error implementation will break a test that assumes the unknown result.main. The reported Linux/Windows repetitions and broader integration run used earlier bases. Please refresh onto currentmainand rerun the focused expiry and socket tests there.The author reports 10/10 Linux and Windows focused runs on the earlier tested head; I did not run network tests locally. I am requesting changes for the unsupported timeout-result assertion and stale integration evidence, not for the expiry fixture's coverage.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T06:09:12Z.
Review: APPROVED
Reviewed — approved
The head merges cleanly onto current
mainand builds.guest_sce_netpasses 10 of 10 runs, and it aborts when the connect deadline is removed. The expiry test already accepts an error code as well as the throw. I found nothing blocking.What I ran
869ec68d9f74285fe3113657c971022bc9e3ff12main:2960e9a6e7e1fc99c4ed180c71495b5eb83464c7, which is 300 commits past the branch's merge baselo(127.0.0.1, ::1).Results
main2960e9a6e7git diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.cmake --build build -j10, includeslibs)guest_sce_net, 10 runsctest -R '(net|socket|ssl|http|rudp|epoll|resolver)'guest_net_ctlis skipped.guest_socket_options_multicastfails, but that comes from the environment (see below)guest_socket_options_multicastonmain'sExport.cppjoining 224.0.0.251 through INADDR_ANY failed (errno 5). It is a libkernel test (guest_socket_options_tests) that does not link the libSceNet export, and the sandbox has no multicast-capable interfaceNetwork test summary (merged tree)
Negative control
core/libs/prx/libSceNet/Export.cppfromorigin/main.guest_sce_netthen aborts after 1.44 s.polltimeout inconnect_withinto-1, so the deadline is ignored.guest_sce_netthen aborts after 2.49 s, through the 1 sstd::asyncguard, so it does not hang.Experiment on the open request. @MarcZX10's review of this head says
CheckConnectTimeoutExpiryonly acceptsstd::runtime_error. That no longer holds at this head.869ec68d9fstores the result and treats any nonzero return as the pending connect (GuestSceNet.cpp:821-831). To check, I replaced the Linux throw withreturn fail(60)(ETIMEDOUT).guest_sce_netpassed 3 of 3 runs. So a later evidence-based error code will not break the test, which also answers @oneandonlydean's request.The same review asks for a refresh onto current
main. The merge onto2960e9a6e7is clean, and the focused tests above pass on it, so I don't consider the branch age blocking.Findings
Blocking
None.
Non-blocking
connect_withinrestores the host flags it read before the wait, which can undo a concurrentSO_NBIO. See Export.cpp:502-514 at the head.flags, and ignores the result.sceNetSetsockopt(SO_NBIO)changes the same host flags without a lock (Export.cpp:1546-1550).SO_NBIOto 1 while a thread waits inconnect_within. When the wait ends, the host socket is blocking again, butnative->nonblockreads 1. The host mode and the guest'sSO_NBIOthen disagree for every later call on that socket.F_SETFLfails.O_NONBLOCKfrom the currentsocket.native->nonblockinstead of from the savedflags, and report a failed restore withnative_error().std::runtime_error". Since869ec68d9fthe test accepts any nonzero result as well. Updating that sentence would stop the request from being raised again.Not verified
selectlimit relies on the author's report and thewindows-latestrun described in the PR.docs/dev/debt/libSceNet.mdand throws, as the rules require.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-30T11:15:41Z.
Review: DISMISSED
The Linux job of the full Build aborts
guest_sce_neton this head, in two separate runs (40983168286 and 41036646524). Both fail the same way:Subprocess abortedafter ~1.9 s, same runner CPU, last log line the second/dev/urandomopen.maindoes not fail this test, and the head only passed Linux earlier (run 40739052906) on an older base, so this is reproducible on the runner and not a flake.core/libs/tests/GuestSceNet.cpp:820-889(CheckConnectTimeout,CheckConnectTimeoutExpiry) are the only new test code that runs at that point, and the abort is a bareRequirewith no message, so the log doesn't say which check failed. Please make the failing check visible (print the line/expression inRequirefor this test, or log the connect results and elapsed times) and find out what differs on the runner from your WSL2 and the Arch runs.wait_foraround thestd::asyncconnect (the 1.9 s total fits one of them expiring), and theECONNREFUSEDcheck against the closed port while other tests run in parallel and may bind it.Push the fix and the queue will build the exact head again; the rest of the change looks fine.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T05:45:40Z.
Review: APPROVED
Re-checked — approved
What changed is commit
056b076ffd, a test-only change, plus a merge of currentmain.Requirenow prints the failing line. The expiry check accepts any number of completed connects before the pending one, and the connect guard is now 5 s. The refused-connect check now targets a port that stays bound. The merged tree builds,guest_sce_netpasses, and both negative controls abort with a readable message.What changed since my last review
056b076ffd(core/libs/tests/GuestSceNet.cpponly):Requireis now a variadic macro overCheck. On failure it prints the line and*sceNetErrnoLoc(), then aborts.CheckConnectTimeoutExpirydrops the!queued.empty()requirement and keeps the cap of 64. Thestd::asyncguard is 5 s instead of 1 s. The loop reports the completed connects, the last result, whether it threw and the elapsed time when it gives up.CheckConnectTimeoutsends the refused connect to a socket that is bound, never listens and stays open until the end. Before, it used the port of the closed listener.95ff923f89: mergesmain5cb015caaa. The production code (Export.cpp) and the debt entry are unchanged since my last review.connect_withinflag-restore note is acknowledged and deliberately left unchanged in this push.What I ran
Head
95ff923f894aac4c9fbc2c425835c8358a9539df,main5cb015caaaaf83f8ee431414ee6a457b5b307d49, merged tree083ea3504f9d3e015eef67e031594553a8ea8e16. Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe.git diff --checkcheck_conventions.pyAll conventions checks passed.libs(script)guest_sce_netagc_driver_image_sample_lod_clamp_shader_lane(reported as a new failure)main'sExport.cpp, so it comes frommain, not from this PR. The PR changes no AGC or shader fileunwrap_self_..._destination_directory_group(reported as a new failure)os.chowngivesEINVALon a temp dir in the sandbox. This is a Python tool test that the PR does not touch, so it comes from the environmentgit status --porcelainis empty.guest_sce_netpasses againNegative-control output
Negative control
Export.cppfrommain:guest_sce_netaborts at the first0x1109check (line 966, errno 45 =EOPNOTSUPP).poll(..., -1)): the test aborts through the 5 s guard and prints its diagnostic line, so it does not hang.Requireoutput names the check that failed, which is what the runner logs were missing.Previous findings
connect_withinrestores the host flags it read before the wait (Export.cpp:562-575): Still open, non-blocking.flagsand ignores the result.SO_NBIOstill changes the same host flags without a lock (Export.cpp:1648-1652).std::runtime_error: Resolved. The description now says it leaves through "thestd::runtime_erroror a nonzero error result".On the others' open requests:
tcp_abort_on_overflow=1) would still abort at the 80 ms check. It now prints a diagnostic line there. That is a non-default sysctl, so I don't count it as a finding.New findings
Blocking
None.
Non-blocking
None.
Not verified
Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-07T10:33:28Z.
Review: APPROVED
Reviewed the non-Windows and Windows connect paths.
connect_withinsetsO_NONBLOCK, polls with the microsecond budget rounded up, readsSO_ERRORand restores the flags; the Windowsselectuses the same budget. The error mapping (net_error->fail) matches the existingfail(native_error())pattern, and the timeout expiry throws as the debt note documents. The tests cover the immediate, refused and expiry cases, including the pending socket'sSO_ERROR/SO_TYPEreadback. No findings.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-08T04:32:47Z.
Review: COMMENTED
Tests run — checks failed, not approved
The build passed; 29 of 77 passed; 39 failed (tls_function_coverage_rejected, tls_function_coverage_displacement_r0, tls_function_coverage_displacement_r1, tls_function_coverage_displacement_r2…); 9 not run for an unknown reason. Not approved: Adaptive build and tests (merged preview): failed, and there is insufficient comparable base evidence to determine whether the PR caused it. Adaptive build
What I ran
Head
af3215f812e1b1ac4baba444c4726af37cdf0f98; base77d2cc9b3626da1844e84829d218723ad40a8300.Recorded local processing time: 12m 25s across no-build checks 8s, build and tests 11m 56s, AI diff review 21s. This sums task runtimes (which may overlap); GitHub Actions time is excluded.
Environment: Linux-6.1.0-54-amd64-x86_64-with-glibc2.36; Python 3.11.2; compiler c++ (Debian 12.2.0-14+deb12u1) 12.2.0.
Saved local build and test runs are listed below; their source and results are in the Test logs section.
I ran the repository's no-build precheck on this exact head and base:
Hosted CI results are read from GitHub; I did not run them.
I compared the full diff of 3 changed files (7,014 lines) with the pull request description. I ran nothing for this and looked at nothing outside the diff.
Results
Findings
Blocking
None in the diff of 3 changed files.
Non-blocking
None recorded.
Not verified
77d2cc9b3626da1844e84829d218723ad40a8300; the later observed base tip(s)06114fe5ce50e0533f7f8614a804e4f730868b4awere not part of those results.To get this to a good state
Test logs (13 entries; open to read)
build_and_compile: not run
Reason:
No output.
diff_check: passed (exit 0)
Command:
No output.
conventions_and_pr_template: passed (exit 0)
Command:
stdout:
changed_export_abi_audit: passed (exit 0)
Command:
stdout:
python_syntax: not applicable
Reason:
No output.
related_python_unit_tests: not applicable
Reason:
No output.
python_test_registration: not applicable
Reason:
No output.
live_dependency_and_mergeability_check: passed (exit 0)
Command:
stdout:
build_dependent_cpp_tests: not run
Reason:
No output.
test_quality_heuristics: passed (exit 0)
Command:
stdout:
negative_controls: not applicable
Reason:
No output.
Adaptive build and tests (merged preview): failed
Result:
Base commit:
Steps:
Tests that failed:
Output of tls_function_coverage_rejected:
Output of tls_function_coverage_displacement_r0:
Output of tls_function_coverage_displacement_r1:
Output of tls_function_coverage_displacement_r2:
Output of tls_function_coverage_displacement_r3:
Output of tls_function_coverage_displacement_r5:
Output of tls_function_coverage_displacement_r7:
Output of tls_function_coverage_displacement_r8:
Output of tls_function_coverage_displacement_r9:
Output of tls_function_coverage_displacement_r10:
Output of tls_function_coverage_displacement_r11:
Output of tls_function_coverage_displacement_r12:
Output of tls_function_coverage_displacement_r13:
Output of tls_function_coverage_displacement_r14:
Output of tls_function_coverage_displacement_r15:
Output of tls_function_coverage_alu_or:
Output of tls_function_coverage_alu_adc:
Output of tls_function_coverage_alu_sbb:
Output of tls_function_coverage_alu_and:
Output of tls_function_coverage_alu_sub:
What did not run, and why:
All tests:
Complete output: 6,994 lines, 0.6 MB: not attached (it stays in the local report)
Hosted CI as GitHub shows it: incomplete
Jobs, newest run of each:
Overall: