feat(libkernel): support deferred cancellation in POSIX accept #12965
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12965"
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 Felipebmaitan on 2026-10-29T17:42:53Z.
What
acceptand_acceptwake on enabled deferred cancellation. The restart state owns an accepted socket through deferred guest delivery. Cancellation or context abandonment releases that socket before guest cleanup and thread-local destructors. A completed native accept wins a pending cancellation request when deferred delivery returns normally.connectand direct libSceNet calls remain outside this cancellation change.Main's checked length copy runs before descriptor lookup. The peer address is copied into guest memory only after reserving the descriptor and allocating its socket-map entry. The entry becomes visible after checked copy-out succeeds. Copy failure releases both the reservation and the connection, including when the copy throws.
TransferKind::Acceptkeeps connected sockets that receivedSHUT_RDon the ordinary accept error path. The focused shutdown tests also cover descriptor aliases.Head
fc8023c3f1a7fb8b06dbeddbaedc9b7c1229f651merges published reads #126827887e7a03da0e8aeed2557f4ba43a6aa777494b9, transport #12688978a8bef6c118f57242b96cee5c6f8cdf493e5d8and writes #127006b8ca980e58f287cb042abf8c09f78f53298aa36, with main integrated through4f5777f2f320111b156ed5db843a6d5f67968923. The prerequisites retain #24939's Linux pending-connectENOTCONNbehavior and #24382's Windows guest buffer checks alongside interruptible socket transfers. The eight-file accept patch has identical additions and deletions to5e7647eafter composing each prerequisite stack. A read-only merge against maine60b2f74adb21151e50567a770ecd8aa795ce415passed before push. GitHub's main-based view includes the prerequisites, so this PR stays draft.Close retries back off from 1 to 16 ms and wake on reader completion. Repeated interruption covers the gap before native entry. An uninterruptible native call can still delay close indefinitely. Setup and admission costs are unmeasured.
The named overlap scan found separate changes in #18476 (libSceNet accept forwarding) and #22573 (inherited socket status flags). A read-only merge of #18476 into the write prerequisite
c76cc79succeeds, while the same merge into5e7647econflicts inUdp.cpp. If #18476 lands first, its forwarding path will need to be reconciled with the staged accept installation here. The dependency order for deferred cancellation remains reads, transport, writes, accept.The overlap report also flags the existing
recvfromandsendtoexports from the composed prerequisites. The accept changes leave both alone. Each NID appears once in the patched Windowslibkernelexport table.Tested
Fresh focused runtime tests on
fc8023c3f1a7fb8b06dbeddbaedc9b7c1229f651ENOTCONNchecks forsend,write, and addresslesssendto.16b2d81failedguest_libressl_ssl_io_transportin hosted Windows CI with exit0xc0000409. A local rebuild of that head reproduced the failure at the handshake retry assertion. The fixture now uses the retained socket's transfer callback, which preserves guest blocking mode. TheEINTRand handshake retry assertions are unchanged. Failing job on16b2d81. Hosted Windows CI passed on5e7647e. Windows job on5e7647e.SHUT_RD, large-file vector I/O, AIO, synchronous write cancellation, andguest_accept_install_copyout_exception. All nine archive fixtures passed on each platform, including checkedpreaddestinations and damaged backing files. The accept copy-out fixture checks propagation of the injected exception, unchanged guest outputs, peer disconnect, and resource counts at cleanup and thread-local destruction. Its resource snapshot begins after connection setup.patched_libraries,net_reuseport_patched,net_ipv6only_patched). The loader reported six patched libraries loaded and zero failures. A loopback smoke test called bothacceptand_acceptby NID in patchedlibkernel. Both copied out the peer address and preserved the queued connection when the guest length pointer was null. PE inspection confirmed patchedlibSceNetimports the three C cancellation helpers exported by patchedlibkerneland has no directThreadCancelimports.origin/main, and diff whitespace passed.A progress scanner comparison counted 719 implemented libkernel exports out of 758 on integrated main
4f5777f2f320111b156ed5db843a6d5f67968923and 708 out of 758 on this head. Replacing one guarded marker in a temporary scanner-only copy restored all eleven labels and the 719/758 count. The marker applies to a blocking Windows stream receive with bothMSG_PEEKandMSG_WAITALL. The scanner follows shared helpers and aliases without evaluating the guard. Accept passes zero flags and sends take the send branch. All eleven exports retain their implementations.An independent review of
500971c926aa02b6ba9045e89844f2e320eb8adcfound that post-install copy-out could leak the descriptor on exception or close a reused number during rollback. Commit142ec9f0df76baff6aa22df10ff2278670191e56stages publication until copy-out succeeds, adds the exception regression and records the remaining limits through the debt fragment. The corrected accept patch is identical to the layer previously published at81d2fef3bfe01c82e842a817b20de0df66d971eb. The counts above are from local rebuilds and tests of the refreshed stack.The intermittent
guest_io_context_sigjumptimeout reported on Windows 22621 remains unresolved. The Windows repetitions above ran on 26300. macOS runtime and console behavior remain unverified for this composition. Original Windows 22621 report.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 CnRJay on 2026-11-01T19:48:59Z.
Review: COMMENTED
Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows
Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.No title ID with a log line reaching
acceptcancellation on main is given ("Unblocks: none", and the limits paragraph says no TCP/cancellation title run). Per the project's usual bar that is the first thing a maintainer will ask for.Not an accept PR as filed. The diff is f66 +7768/-263 because it carries #10817/#10755, #12682, #12688 and #12700 as a stack. Reviewers cannot read the accept slice (the stated 7 files, 249 insertions) in this view, and the same commits are being reviewed in the prerequisite PRs. Please keep this as a draft until the stack merges, or retarget so the diff is only the accept change.
A known hang is shipped open. The body says the Windows 22621
guest_io_context_sigjumphang "remains unexplained" and the update "adds a bounded diagnostic guard, not a claimed lost-wake repair". A ready PR should not merge with a reproducible hang in the cancellation path under test; either explain it or mark the PR draft.1 ms poll in the Close path. In the descriptor-access code the
Mode::Closewait iswhile (!CanChange()) { state->Interrupt(); changed.wait_for(lock, 1ms); }. That re-issuesInterrupt()every millisecond for as long as any reader is in flight, instead of waiting on a notification from the reader. If the reader is blocked in a long native call (anacceptwith no pending connection is exactly that), this wakes at 1 kHz and re-takes the state mutex each time. Please say why a singleInterrupt()plus a predicate wait is not enough, and what bounds the loop.Limits listed but untested. "Descriptor-installation failure and disposal ordering before cleanup/TSD are statically reviewed, not directly fault-injected." The ownership transfer of an accepted socket across a deferred-cancel boundary is the part that leaks descriptors if wrong; a fault-injection test with a count of open descriptors before and after would be the negative control.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T21:54:02Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this review; the points below are optional.
What I ran
Reviewed head
99dee9956598573e0f66bd0dae68040cfad574ad. No commands or tests were run in this review. I read the prepared description, commits, manifest, and diff, plus the accept cancellation, restart ownership, and socket installation code usingrepo_read.py. All files markedreviewedin the manifest are included, but the full text of every changed file was not read.Results
Findings
Blocking
None.
Non-blocking
Not verified
I did not review every changed file or independently verify the broader prerequisite changes, author-reported test results, CI, or console behavior. No files were excluded by the prepared review manifest; the review was targeted to the accept cancellation path and its ownership/install context.
To get this to a good state
Nothing is required. Optional: add fresh composed-head Linux and macOS results and continue investigating the Windows 22621 hang.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T22:23:58Z.
Review: COMMENTED
Reviewed — no blocking findings
The accept cancellation and staged socket installation paths are supported by the inspected code and focused tests; the broader composed change was not reviewed completely.
What I ran
No build or tests were run. The description reports focused test runs, but these were not independently verified here.
Results
Findings
Blocking
None in the code inspected.
Non-blocking
None.
Not verified
The inspected repository files were
core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/prx/libkernel/Pthread/include/Cancel.hpp,core/libs/prx/libkernel/Pthread/src/IoSignals.cpp,core/libs/prx/libkernel/Pthread/src/NativeIo.cpp, andcore/libs/tests/GuestAcceptCancel.cpp. The diff and manifest were read in selected ranges. Most other changed files listed as reviewed inreview/manifest.jsonwere not read; their behavior, tests, and interactions are not verified.docs/dev/debt/changes/posix-socket-blocking-transport.mdwas excluded by rule. No build, runtime tests, or console behavior were checked.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files and independently run the focused suites before relying on the broader composed change.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T00:08:40Z.
Review: COMMENTED
Reviewed — comments
The accept cancellation path was reviewed at head
2e68c87b9986edef7123f0cfbdf1ee7ae60eba6b; I found no verified blocking defect, but the broader change was not fully reviewed.What I ran
Read the prepared description, commits, manifest and diff, then inspected the changed accept implementation and cancellation interface through
repo_read.py. No tests or builds were run.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
None.
Not verified
This was a targeted review, not a complete review of the changed code. I read
core/libs/prx/libkernel/Socket/src/Udp.cppandcore/libs/prx/libkernel/Pthread/include/Cancel.hppfor repository context. I did not read all changed files or run tests. The description reports Windows 11 and Debian 12 test results; these were not independently verified. macOS runtime and console behavior are reported as unverified by the author. The bundle’s excluded-by-rule file isdocs/dev/debt/changes/posix-socket-blocking-transport.md.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files and run the focused tests on this head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:13:19Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete, so a formal approval is not justified; the inspected accept and descriptor paths showed no verified blocking defect.
What I ran
Reviewed head
34f53aac67749d5c76d21aa106b127990396fa4afrom the prepared diff. I did not run commands or tests; the test results in the description are author-reported.Results
Negative control
Not run; no tests were run in this review.
Findings
Blocking
None verified in the inspected code.
Non-blocking
No code-level feedback from the inspected paths. This review remains a comment because most changed files were not inspected.
Sources
Not verified
I read
description.md,commits.md,manifest.json, anddiff.patchfrom the prepared review materials. Among changed repository files, I inspectedcore/libs/prx/libkernel/Pthread/include/Cancel.hpp,core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/prx/libc/src/DescriptorAccess.cpp,core/libs/prx/libc/include/DescriptorAccess.hpp,core/libs/prx/libkernel/File/include/File.hpp, andcore/libs/prx/libkernel/File/src/DescriptorControl.cpp. I did not inspect the remaining 74 changed files or run tests. The description identifiesdocs/dev/debt/changes/posix-socket-blocking-transport.mdas excluded by rule.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files and run the focused tests on this head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:12:02Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
16b2d81e0dca6f215e2dafcfc4e29e283c156c15using the prepared diff andrepo_read.pyat the pinned head. No commands or tests were run. The description reports Windows and Linux test runs; those results are author-reported, not independently verified.Results
Negative control
Not run; no tests were run in this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
The prepared diff and pinned source review support the behavior claims. Key reviewed paths:
core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/prx/libkernel/Pthread/include/Cancel.hpp,core/libs/prx/libkernel/Pthread/src/IoSignals.cpp,core/libs/prx/libc/src/DescriptorAccess.cpp, andcore/libs/prx/libc/src/JumpBuffer.cpp.Not verified
I did not read every changed file or independently verify the author-reported Windows, Linux, patched-library, or public-header checks. macOS runtime and console behavior are reported as unverified in the description.
docs/dev/debt/changes/posix-socket-blocking-transport.mdwas excluded by rule.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T06:55:32Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete: only selected implementation files and hunks were inspected, so a formal merge decision is not justified.
What I ran
Inspected the prepared review documents and selected source ranges at head
5e7647e0824841f1c772b7cc44b1a548060b8ed2using therepo_read.pyreader. No build or tests were run; test results in the PR description are author-reported.Results
Findings
Blocking
None identified in the inspected portions.
Non-blocking
None identified in the inspected portions.
Not verified
The changed files read were
core/libs/prx/libSceLibreSsl/tests/FakeSocket.hpp,core/libs/prx/libc/src/DescriptorAccess.cpp,core/libs/prx/libc/src/JumpBuffer.cpp,core/libs/prx/libkernel/File/src/DescriptorControl.cpp,core/libs/prx/libkernel/File/src/Stdio.cpp,core/libs/prx/libkernel/Pthread/include/Cancel.hpp,core/libs/prx/libkernel/Pthread/src/IoSignals.cpp,core/libs/prx/libkernel/Pthread/src/NativeIo.cpp, andcore/libs/prx/libkernel/Socket/src/Udp.cpp. Some were only partially read. The description, commit list, manifest, diff, and review-folder README were also inspected.The other changed files listed in the manifest were not read, and the changed lines in the partially read files were not all checked. The excluded files listed by the review folder were not inspected. Builds, tests, macOS runtime, and console behavior were not verified. The PR description's test results were not independently confirmed.
To get this to a good state
Nothing is required. Optional: complete the changed-line review and run or independently confirm the relevant checks before making a formal review decision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T09:05:48Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this draft; the remaining checks and platform behavior listed below were not verified.
What I ran
Inspected the prepared diff and targeted source at head
fc8023c3f1a7fb8b06dbeddbaedc9b7c1229f651usingrepo_read.pyreader tools. No build or tests were run in this review.Read the prepared description, commit list, diff, manifest, and targeted ranges from
core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/prx/libc/src/DescriptorAccess.cpp, andcore/libs/prx/libkernel/Pthread/include/Cancel.hpp. The manifest marks every changed file included; the separatefiles.jsonwas unavailable through the reader. Excluded by rule:docs/dev/debt/changes/posix-socket-blocking-transport.md.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The patch spans many files; targeted source reads focused on descriptor coordination, cancellation helpers, and socket transfer/accept paths. I did not read every changed file in full or independently reproduce the author-reported test results. macOS runtime, physical-console behavior, and the reported Windows 22621 timeout remain unverified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:53:58Z.
Review: COMMENTED
ReportAddresswrites the peer bytes before it checks whether the length can be written. The new copy-out exception fixture throws beforeReportAddress, so its untouched-output assertion misses a failure of the second write. Could the fixture cover both output destinations independently and assert the intended peer-buffer contents afteracceptreturnsEFAULT? If that case should leave both outputs unchanged, check both guest spans before copying the address.Source review at
fc8023c3f1. A trial merge onto484e8e6b77conflicts in the inherited libc and socket changes, preventing an integrated run on that base.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.