Skip to content

test(http2): guard allocation-free handle teardown - #9598

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
Ondra97:codex/fix-http2-teardown-ownership
Oct 27, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
Ondra97:codex/fix-http2-teardown-ownership

Conversation

@Ondra97

@Ondra97 Ondra97 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Keep regression coverage for allocation-free HTTP2 handle teardown on the current transport backend. Main's synchronous transport implementation already replaced the temporary-vector cleanup and removed the old offline completion queue, so this rebased PR changes only the test and its CMake registration. Production Export.cpp is byte-identical to the base.

The fixture calls the canonical public header and compiles the current production Export.cpp and Cookies.cpp with the real transport dependency, allowing its replacement C++ allocator to observe teardown allocations. It checks request, template and context deletion under budgets 0–15: descendants disappear, neighboring templates and independent contexts survive, cookie boxes retain their separate ownership, and deletion makes no allocation attempt. The one-shot fault disarms before throwing so exception unwinding can allocate.

The 192 concurrent cases now race child creation against deletion and check that no created handle escapes its parent's teardown. The removed async completion model is not restored. The new fixture covers unsent handles; existing HTTP2 transport fixtures remain registered and are included in the validation selection.

Tested

Base ea048ce2c35e1fb65ea3331ed73bba35cb27e584; tested head 7a0dfeb79c3d440738cf87762eafe07c96ceb1cf. Windows 11 Pro 10.0.26300, Ryzen 9 7900X, 31.7 GiB RAM, RTX 4070 Ti SUPER; WinLibs MinGW-w64 GCC 15.2.0 r7 UCRT, CMake 4.3.1, Ninja 1.13.2, Release, BUILD_TESTING=ON, pinned bundled dependencies. CPU and local socket fixtures.

  • Built libs, patched_libraries_tests, guest_http2_tests, guest_http2_cookie_tests, guest_http2_transport_tests, guest_http2_teardown_tests, guest_http_tests, guest_http_response_header_tests, guest_http_options_tests, guest_ssl_tests, guest_ssl_load_tests, guest_ssl_transport_tests, guest_ssl_ps5_readers_tests and guest_sce_net_tests with cmake --build <build> --target <targets> --parallel 8.
  • ctest --test-dir <build> -R '^(guest_http2.*|guest_http(_response_header|_options)?|guest_ssl(_load|_transport_kernel|_transport_net|_ps5_readers)?|guest_sce_net|patched_libraries)$' -V --output-on-failure --no-tests=error --repeat until-fail:3: 16/16 passed in all three repetitions, zero skips, 19.56 s total, outside the sandbox so the local socket fixtures can run. Each library-load check loaded 368 patched libraries, zero failures.
  • Each teardown run completed 48 allocation-pressure lifecycles and 192 concurrent lifecycles with zero failures.
  • Mutation control: temporarily restored vector-based descendant collection in the current production helper, preserving transport shutdown. The same registered teardown test rejected it with 32 failing allocation-pressure cases and exit 1. I restored Export.cpp byte-for-byte, rebuilt, and reran the complete green selection. This is a deliberate mutation, not a claim that current main still contains the original bug.
  • ctest --test-dir <build> -R '^public_headers($|_compile_)' -j 4 --output-on-failure --no-tests=error: 65/65 passed, zero skips.
  • Conventions, strict main-sync, whitespace and registration checks pass. The registration audit counts 1,448 test executables, with none unregistered; the executed selection is the 16 tests above.
  • tools/pr_overlap.py completed. Its test(http2): guard allocation-free handle teardown #9598 entries refer to this existing PR under its old branch head. test: organize library tests and label CTest suites #6044 is closed. The remaining uncomparable feat(libSceHttp2): create WebSocket requests and answer them as a PS5 does before they connect #11470 CMake edit adds libSceHttp to the production library's link dependencies, separately from this PR's new test target; I inspected that edit manually.

No full CTest suite, title or console run is claimed. Earlier offline-completion measurements and Linux reports apply to the old implementation and are not evidence for this rewritten fixture.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The teardown now erases descendants and queued completions while holding the existing handle-then-completion lock order, without allocating temporary vectors. I checked that submission uses the same lock order and WaitAsync takes only the completion lock; the new fault-injection and submission/deletion tests cover the main ownership paths. The PR report is unusually clear about synthetic scope, actual executed counts, the temporary #8310 build overlay, and unverified console/event behavior. The intervening commits since tested base d9c99c9 are documentation-only, so they do not affect this implementation or the reported focused tests. Hosted conventions, eligibility, intake, labels and report checks pass; hosted product/relinker jobs are skipped. The Windows build/tests are author-reported, with an independent test comment also present. I did not run tests locally.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux run, since the description lists only Windows 11. The fix passes, but on Linux the test cannot show its red: with the base Export.cpp it hangs until the 30 s ctest timeout instead of printing the failure counts.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04 (kernel 7.0.0-38), GCC 15.2, Release, BUILD_TESTING=ON. Head fdd048978 merged --no-commit onto main ab347d144 (clean).

  • With the PR: guest_http2_teardown and guest_http2 pass, 3 of 3 runs.

  • Base Export.cpp plus this test: guest_http2_teardown is ***Timeout 30.04 sec, with no output. The process is single-threaded and parked in a futex. Backtrace (gdb, first lifecycle, DeleteRequest at budget 0):

    #1  pthread_mutex_lock
    #2  LibcUnwind::FindFrameFast(LibcUnwind::Lookup&)      libc.prx
    ...
    #6  _Unwind_RaiseException_nid_postfix                  libc.prx
    #7  __cxa_throw_nid_postfix                             libc.prx
    #8  operator new(unsigned long) [clone .cold]           test
    #9  LibcUnwind::FindFrameFast(LibcUnwind::Lookup&)      libc.prx
    ...
    #14 __cxa_throw_nid_postfix                             libc.prx
    #15 operator new(unsigned long) [clone .cold]           test
    #16 sceHttp2DeleteRequest
    #17 main
    

    On this build the test executable's throw goes through libc.prx's unwinder. FindFrameFast allocates while it holds its lock, the replaced operator new is still at budget 0 and throws again, and the nested throw blocks on the same lock. So any regression that allocates in teardown shows up on Linux as a timeout, not as the threw=… ownership=… lines.

  • Disarming the budget before the throw fixes that here:

    if (allocationBudget == 0) {
        allocationBudget = -1;
        throw std::bad_alloc();
    }

    With that change, base Export.cpp prints 48 failures (23 with threw=1), which matches the 23 bad_alloc in your table. With the PR it prints 0 failures (3 of 3 runs). The PR's own result doesn't change, because the fixed teardown never allocates under the budget.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@Ondra97
Ondra97 requested a review from jotitadev October 22, 2026 05:58

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ran on Linux after 99d261595 (budget disarmed before the throw).

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release. Head 58e6b6b56 merged --no-commit onto main d6eafa54d (clean).

  • With the PR: guest_http2_teardown prints 48 allocation-pressure lifecycles, 192 concurrent lifecycles, 0 failures, 3 of 3 runs. guest_http, guest_http2, guest_http_options and guest_http_response_header also pass.
  • Base Export.cpp plus this test: no more timeout. It exits 1 in 0.02 s with 48 failures, 23 of them threw=1, which matches the Windows table.

So the red is now visible on Linux as well.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@MarcZX10

Copy link
Copy Markdown
Contributor

Rechecked the current head after the independent Linux follow-up: the approval still stands, and exact-head conventions plus whitespace checks pass. The Linux reviewer now reports 3/3 green runs and a visible 48-failure base control after the injector disarms before throwing. #6044 changes the broad CMake test naming/registration scheme but does not touch the HTTP2 implementation; please resolve/rebase the test-registration overlap and rerun registration/build checks after its merge if needed.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure-atomic teardown fix still has strong Windows evidence and an independent Linux red/green run after the allocator injector was made unwinding-safe. Exact head 58e6b6b5653d888955b39924beaf17f1f1a4dc0f passes current-main whitespace and conventions checks; the current-main merge tree is clean. I also syntax-compiled Export.cpp and Http2TeardownFailure.cpp with GCC 12.2 (suppressing existing unused-parameter/missing-field warnings in Export.cpp). I did not run the runtime tests locally.

The branch is based on b27924d851696cafcb83152515f1c84d8804e1f3, behind current main 3ca07d086d5f44fbe3c00370e7f03953ab46ca1b. Please update to current main and refresh focused tests, conventions, and registration checks. #6044 remains open and its test reorganization overlaps the broad CMake changes; the direct merge reports no conflict in this PR's libSceHttp2/CMakeLists.txt, but please preserve the guest_http2_teardown registration and rerun its build/registration checks after either branch is rebased. This request is only for the current-main and test-registration update; the code approval stands and the obsolete intake hold is withdrawn.

@blawesom

Copy link
Copy Markdown
Contributor

Independent verification of the outstanding ask (current-main refresh + refreshed focused rerun) as a combined both-stacks run — I ran the integration the comments above requested coordination on, on a local merge of both this stack and #9630's (their diffs are disjoint: libSceHttp2 vs libSceHttp). I did not modify this branch.

Heads

  • main (local mirror of origin/main) 4b1a9a3b2f
  • PR head c730b0457c
  • Tested head ba4ed7bd8b: a local no-conflict merge of PR head c730b0457c and PR fix(http): preserve context and epoll state on allocation failure #9630 head f66f955da7 into main 4b1a9a3b2f. Branch cycle4-http-allocation on blawesom/AnyPS5, rerun without recomputing the merge. git diff --shortstat main ba4ed7bd8b = 8 files changed, 437 insertions(+), 49 deletions(-) — both PRs' claimed scopes combined (4 files each).

Results (same machine, same build, parent vs change)

Arch Linux (CachyOS, kernel 7.2.10-1-cachyos), GCC, Ninja, BUILD_TESTING=ON. Builds: Release, and Debug -DANYPS5_ENABLE_ASAN=ON. Base control rebuilt from the same test sources and registration with only both production Export.cpp files restored from current main, so the diffs are the production fixes alone.

Test base (main's Export.cpp) both changes ba4ed7bd8b
guest_http2_teardown fail pass
guest_http_state_* (the #9630 stack, run in the same session) 6 of 7 fail pass

Base: 7 of 8 fail, 3 consecutive runs identical. Change: 8/8 pass, 3 consecutive runs each in Release and ASan (12 runs total), each run reports 100% and no ASan report. In the base runs this PR's teardown failure is the deletion/erase path under allocation pressure (the log's completion survived deletion: request=2054 live=0 line is from the sibling suite's base run in the same batch). The sibling suite's single base-passing case (guest_http_state_term_3, budget that never triggers the bug here) shows a fixture that does not simply assert everything fails.

Conventions: python3 tools/check_conventions.py --base origin/main passes on the tested head; git diff --check is clean.

Not run: Windows, macOS, a title, console. The combined-stack caveat from the discussion above still stands: this establishes the teardown fix works together with #9630's on local Linux/ASan bookkeeping behavior, not console child-handle lifetimes or cancellation of already-posted events (recorded in this PR's debt).

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 11470 core/libs/prx/libSceHttp2/CMakeLists.txt
PR 11611 core/libs/prx/libSceHttp2/CMakeLists.txt

@Ondra97
Ondra97 force-pushed the codex/fix-http2-teardown-ownership branch from c730b04 to 7a0dfeb Compare October 27, 2026 08:01
@Ondra97 Ondra97 changed the title fix(http2): keep teardown consistent under allocation failure test(http2): guard allocation-free handle teardown Oct 27, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 27, 2026 08:08

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@adriadam10
adriadam10 merged commit 2ee8e97 into boykopovar:main Oct 27, 2026
11 of 12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Rechecked the rebased head: production Export.cpp is unchanged from main (allocation-free ReleaseOwnedHandles), guest_http2_teardown is registered and links the real Export.cpp/Cookies.cpp/transport, the allocation fault disarms before throwing, and the budget 0-15 and concurrent create-vs-delete cases pin zero allocation attempts and parent ownership on request, template and context teardown; merged.

@Ondra97
Ondra97 deleted the codex/fix-http2-teardown-ownership branch October 27, 2026 21:16
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.

5 participants