fix(http): preserve context and epoll state on allocation failure #9630
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9630"
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 Ondra97 on 2026-10-22T05:11:44Z.
What
Allocation failure can leave HTTP context or epoll ownership partly published. Initialization now treats main's pool-size registry, registered net/SSL IDs, context set and option initialization as one transaction: if any insertion fails, the unpublished context's entries are removed and existing contexts remain usable. Epoll handles are written only after registry insertion succeeds. Last-context termination detaches the existing epoll map with
swap, avoiding an allocating teardown list after context removal.The public-header review is addressed by including
prx/libSceHttp/include/Http.hppinHttpStateAllocation.cppand removing all seven local export redeclarations. The one-shot allocation injector remains disarmed before throwing, so exception unwinding cannot reinject the same synthetic fault.The current-main refresh also closes the rollback gap introduced by the two newer registries. The live-context regression queries both public registry APIs for the unpublished ID and checks that the existing context's pool stats and registered IDs remain valid. The fixture derives the attempted ID from this implementation's monotonic initializer; it makes no PS5 handle-layout claim. PS5 OOM errors and failed-call outputs remain unmeasured in debt, and creation may still throw
std::bad_alloc.The agreed order remains #9630 before cookie-store #10535 and draft transport #9834. #11134 depends on #9834 and carries its transport integration. None is a prerequisite for this standalone bookkeeping fix. Future composition must retain rollback across all registries and preserve both test blocks. The cookie/transport source and link additions discussed in the thread remain required for their combined allocation target; no new combined-stack run is claimed here.
Tested
Revalidated on 2026-10-30: base
556547da71c5e25b742f17b1ed9b27253b6e9d4d, submitted headcff855f72618fbee7bde0b866609854017ca5f9b. Main was merged into the existing branch, retaining the original allocator and epoll patches.Windows 11 Pro 10.0.26300, AMD Ryzen 9 7900X, 31.7 GiB RAM, NVIDIA GeForce RTX 4070 Ti SUPER (unused by these CPU tests); WinLibs MinGW-w64 GCC 15.2.0 r7 UCRT; Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON, pinned bundled dependencies.relinker/libs, patched-library checker and all selected HTTP/HTTP2 test executables built successfully on the submitted sources.failed init retained its pool-size registrationon the header-fixed tree with the old rollback. Moving all three main-side registrations into the transaction and erasing them on failure makes the same test pass. The options registry insertion has the container's strong failure guarantee. The full suite and repeated allocation cases were then rerun on the final sources.Conventions, strict main synchronization, whitespace and registration checks pass. The overlap report identifies #9834/#11134's transport transaction and #10535's adjacent CMake registration; the shared hunks were inspected and the existing dependency direction is retained. The transport variants already carry their own additional registry rollback, which must be combined with this standalone fix. No peer implementation was copied into this branch and no transport/cookie combined runtime validation is claimed.
No title, console, complete CTest suite or native Linux run of this refreshed head is claimed. The reviewer's Linux header/build/red-control results concern the stated earlier head and local header patch. Earlier author validation below remains historical.
Earlier submitted-revision validation (historical)
Windows 11 Pro 10.0.26300; AMD Ryzen 9 7900X, 31.66 GiB RAM, NVIDIA GeForce RTX 4070 Ti SUPER. WinLibs GCC 15.2.0, Ninja Release,
BUILD_TESTING=ON,ANYPS5_RELINKER_ONLY=OFF, bundled dependencies.Current main base:
b7d1d47a5f9f32c9c388ad8d47a0055a90ae6e33. Tested head:f66f955da716869c32b74a0d822e4ddea71ca43e. The regression executable compiles productionExport.cppandOptions.cppdirectly so its replacement C++ allocator reaches the real bookkeeping code. The red control and the Before values below were measured on the earlier based6eafa54d0464258574fd2f71889754d05a5bc93; I did not rerun that control on the new base. The HTTP implementation and regression source were unchanged by the main merges. The original HTTP tests separately exercise the shared library.With the one-shot injector, the unchanged base failed 6/7 new lifecycle tests in 0.25 s: initialization left partial state at budget 2 without an existing context and at budget 1 with one; epoll insertion changed the output in two failed calls; termination lost the context at budgets 0-2. The fix passed all 7 new tests and 28 budget scenarios: 8 for each initialization mode, 8 for epoll creation and 4 for termination. The base initialization probes stop at their first invalid state, so they do not complete all 28 scenarios. Successful epolls support polling/deletion, existing contexts survive failed creation, failed outputs remain untouched, and a fresh context cannot use epolls from a completed termination. No title or console was run.
The full all-target Windows build passed on the final head with
BUILD_TESTING=ON, bundled dependencies and the complete default AGC execution-test set. #8310 is merged in the base; no source overlay was used. An initial sandboxed build stopped in the libusb version generator because Git Bash/MSYS could not create a named object (0xC0000022); the same incremental build completed outside that sandbox.Final selected runtime tests: 12/12 passed, 0 skipped; 367 patched libraries loaded, 0 failed. Both changed translation units compile; conventions, registration (1,176 test executables, none built and unregistered), main-sync and whitespace checks pass. Registration is an executable count, not an executed-test count.
Commands, with the supported WinLibs toolchain on
PATHand the full Release build configured in a sibling../builddirectory:All commands above used the final submitted sources. The earlier red control temporarily compiled the regression target with unchanged earlier-base
Export.cpp, then restored the source before the final build.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 fogydes on 2026-10-22T08:13:31Z.
The two failure paths are fixed the right way, verified against the diff:
sceHttpCreateEpollonly writes*ehafter the map insert succeeds (so nothing is published and the caller's value survives a throw),sceHttpTerm_nid_postfixswaps the whole map out under the lock instead of a move-out loop (no half-moved epolls left behind by a throw), and a failedAddHttpContextinsceHttpInitrolls back the context id it just registered. The injectedbad_alloctests cover both directions (rejected and shrinking-budget success), including the output invariants.Two nits, neither blocking:
CMakeLists.txtnow carries twoif(BUILD_TESTING)blocks whose tail duplicates the WindowsPATHfixup for the same test directory; one block would be simpler.The term test walks budgets 0..3 while the init/create tests walk 0..7, so the term path sees fewer allocation-fault positions than its siblings do.
No conventions problems: no comments added, the debt entry records exactly what remains unverified (console OOM error values and failed-call outputs), and the inline
// No network is emulated...comment predates the PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:22:48Z.
Review: CHANGES_REQUESTED
The allocation-failure fixes match the ownership invariants: init rolls back the inserted context, epoll output is published only after registry insertion, and termination swaps the existing map instead of allocating a teardown vector. The one-shot allocator avoids recursive fault injection during unwinding. The author reports 7/7 regressions on the fix versus 1/7 on base, plus 0/8 output changes after failed epoll creation, 11/11 selected runtime tests and a full Windows build. An independent review agrees with the key failure paths. I ran exact-head
git diff --checkand current-main conventions; both pass. Full hosted product jobs are skipped on this head, so the Windows results are author-reported; I did not rerun them locally. Minor test coverage note: termination explores budgets 0–3 while init/create explore 0–7, and CMake has duplicated Windows PATH setup; neither changes the core disposition. The change is generic withUnblocks: none. Coordinate merge order with #8357 as stated in the description.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:57:24Z.
Review: CHANGES_REQUESTED
The allocation-failure fixes and regression results remain convincing. I independently ran exact-head whitespace/conventions checks, test registration (171 scripts), and Linux syntax checks for the changed HTTP implementation, options unit, and allocation test; all passed. The author reports 7/7 allocation regressions, 0/8 failed-create output mutations, 11/11 selected runtime tests, and a full Windows build. Product jobs are path-skipped in hosted CI, so those runtime results remain author-reported here.
I am withdrawing my earlier #5239 intake hold as a reason to defer this PR. The remaining repository requirement is a current-main base: this targets
d6eafa5, whilemainis 15 commits ahead at8b3a6ba. The intervening commits do not touch the HTTP files changed here, so the update should be low risk; please rebase and refresh conventions/overlap checks before merge. The ordering with #8357 is already agreed by both authors: this fix first, then #8357 rebases and carries rollback through its pool registry.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:24:16Z.
Review: APPROVED
The exact head
f66f955da716869c32b74a0d822e4ddea71ca43epreserves the intended rollback invariants: failed initialization removes the unpublished context, epoll output is not published before registry insertion succeeds, and termination swaps the existing map instead of allocating during teardown. The author reports 7/7 lifecycle regressions on the fix versus 1/7 on the base, plus 11/11 selected HTTP tests and a full Windows build. An independent Windows run of the same head merged onto currentmainreports all 10 libSceHttp tests passing. The earlier Linux syntax, conventions, overlap, and test-registration checks also passed; hosted product jobs remain path-skipped, and I did not rerun a local build.The order with #8357 and #10535 is documented, and the dependent #9834 author has been told its allocation test target needs source/link changes when stacked. No blocking correctness issue remains in this PR. Approved.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T14:05:46Z.
Review: COMMENTED
Merging this head into current
mainbreakspublic_headers.Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Headf66f955da7merged (--no-commit) ontomainf91137142e. The merge is clean, and the 7guest_http_state_*tests pass 3/3.public_headersfails. The PR's baseb7d1d47a5fpredates #10706, which requires each export to be declared once, in its library's public header. Theextern "C"block inHttpStateAllocation.cppdeclares 7 exports again thatprx/libSceHttp/include/Http.hppalready declares:The same happens for
sceHttpInit_nid_postfix,sceHttpTerm_nid_postfix,sceHttpAuthCacheFlush,sceHttpGetNonblock,sceHttpDestroyEpollandsceHttpWaitRequest. The build CI doesn't run on PRs, so it didn't show up here.Including the header instead of the block fixes it:
With that change, on the same merge:
public_headersand the 64public_headers_compile_*tests pass (65/65).guest_http_state_*tests pass 3/3, and all HTTP/HTTP2 tests pass (19/19).Export.cppfrommain, 6 of 7 fail 3/3 (init,init_live,create_epoll,term_0toterm_2), the same as your red control.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T20:18:06Z.
Review: COMMENTED
Re-checked
cff855f726on Linux:public_headerspasses now.Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Head merged (--no-commit) onto currentmain16345cad6a; clean merge, full build OK.public_headers, the 64public_headers_compile_*tests and the 7guest_http_state_*tests: 72/72, 3 of 3 runs.Export.cppfrommain, 6 of 7guest_http_state_*still fail 3/3 (init,init_live,create_epoll,term_0toterm_2), same as before.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.