XGameRuntime: avoid leaking Mount handles in mount_with_ui_async #1232
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1242"
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 ivall/xcl. Originally posted by b3IKK on 2026-11-24T13:39:51Z.
mount_with_ui_asynccalledXPackageMount(allocatingBox<Mount>) beforebegin_withvalidated theXAsyncBlockor scheduled work. Ifbwas null (E_INVALIDARG) or its task queue was already terminated (E_ABORT), the allocatedMounthandle was never returned to the caller and leaked permanently.This copies the optional package identifier and performs
XPackageMountinside thebegin_withwork closure soMountis only allocated when the async work runs.What is in it
crates/xcl/src/hle/xgameruntime/api.rs: moveXPackageMountinside thebegin_withwork closure inmount_with_ui_async; add unit testmount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_call.crates/xcl/src/hle/xgameruntime/mod.rs: add#[cfg(test)]LIVE_MOUNTScounter inXPackageMount/XPackageCloseMountHandlefor the leak test.This is now the only PR from this account that changes
mount_with_ui_async: the mount part was taken out of #1610 (#1607, group D68), so the two do not compete for the same lines.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 994 passed, 0 failed, 45 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses,no heap windows, andcannot disable the driver cache (Windows Developer Mode is required))cargo test -p xcl --lib -- mount_with_ui_async: 1 passed, 0 failed. Withmount_with_ui_asyncput back tomain's version and the test kept: 0 passed, 1 failed —Mount leaked on null XAsyncBlock.Regression run
main (
80f4819, clean tree, no local changes):PR (
7124d1e, clean tree, no local changes):Not tested
mount_with_ui_asyncwith a terminated queue (the test builds that call)AI use
xgameruntime/api.rs, wrote the fix and the regression test (and confirmed it fails with the old function), rebased onto80f4819, ran the test suite and thescripts/smoke.ps1runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T13:45:19Z.
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on
main@930e8b4(baseline 751 passed, 0 failed, 41 ignored on this box):One more than the baseline; the XGameRuntime mount-handle leak fix is exercised and green.
Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:02:05Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-25T00:14:56Z.
Rebased onto
80f4819(mainhad added a test at the same place inapi.rs; both are kept) and re-ran: 994 passed, 0 failed, 45 ignored. This is now the only PR from this account that changesmount_with_ui_async: #1610 no longer does. Againstmain's function the test fails withMount leaked on null XAsyncBlock. AI use: OpenCode, Claude Fable 5.2.upstream-sync referenced this pull request2026-11-25 06:04:27 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:32:26Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:20:32Z.
merge-check claim
head:
7124d1efabImported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:28:27Z.
merge-check
base:
d0832e614fhead:
7124d1efabmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same run: 2890 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The new test
mount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_callran and passed.review: no blocking finding; two files (+54/-7), every line read.
mount_with_ui_asyncused to mount first and start the async operation second, so a refused start (null block) or a terminated queue left aMountnobody could close; it now copies the identifier and mounts inside the operation's work closure. Two things to know, neither blocking: (1) an unknown package identifier is now reported through the async status (XAsyncGetStatus/ the result call) instead of as the return value of the...Asynccall itself; (2) a title that completes the operation and never fetches the result still leaves that mount open, as before this PR. TheLIVE_MOUNTScounter exists only under#[cfg(test)]; it is process-wide, so a later test that mounts in parallel would disturb this one; I found no other direct call ofXPackageMountin the crate today.performance: none: the mount (one small allocation) moves from the caller's thread to the async work item.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:13:15Z.
Triage (#1607) – head
7124d1eNo open or merged PR makes the same change. #1610 (grouped with this one in #1607) changes QueryInterface identity and forwarding aliases in api.rs, unrelated to
mount_with_ui_async.Moving
XPackageMountinto thebegin_withwork closure means a null block or a terminated queue no longer leaks aMount, and the id is copied so it outlives the call. The test'sLIVE_MOUNTScounter is safe as long as no other test mounts in parallel (none does on main today).#1247 also touches
mount_with_ui_resultnext to this function; expect a textual conflict, not an overlap.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by cj-tomlin on 2026-12-02T17:13:26Z.
Test report, head
7124d1efab59ad2cadbecee8c95a356dfa6188b4merged ontomain5eaadb54c14e0fc29597b2a1689d7dbd83491303(clean, mergee9ac08f2).cargo build --workspace: ok.cargo test --workspace --no-fail-fast -- --test-threads=4: 2975 passed, 0 failed, 52 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll), the same 27 as plainmain(2974 passed, 0 failed, 52 ignored) on this machine.mount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_callpasses, and fails withMount leaked on null XAsyncBlockwhen I putmain'smount_with_ui_asyncback into the merged tree.Diff read (+54/-7,
xgameruntime/api.rs,mod.rs), CPU only. Two behaviour changes beyond the leak, not blocking: anXPackageMountfailure (e.g.E_NOT_FOUNDfor an unknown package) now comes back throughXAsyncGetStatusinstead of as the call's own return value, and an id that is not valid UTF-8 now reachesXPackageMountas null.Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.
Imported from ivall/xcl. Originally posted by Pipodi on 2026-12-02T22:08:55Z.
merge-check
base:
5ad98adbc3head:
7124d1efabmerge: clean (
git merge --no-ffonto5ad98adb, merge d54cc037; xgameruntime/api.rs +47/-7, xgameruntime/mod.rs +7)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3006 passed, 0 failed, 52 ignored; failing: none (SKIPPED 25: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache). The new xgameruntime::api::tests::mount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_call passes.
title run: retail title on NVIDIA GeForce RTX 4090, no save, into the in-engine intro cutscenes: 376 s in the cutscenes (log 58-434 s, from the first 2 s window with cutscene draws to the end), 0 device removals, 0 crashes (exit 0x0, ended by XCL_RUN_SECONDS=420), 3.86 presents/s in the cutscenes (1452 presents in 376 s, from the log's 2 s activity lines; 2559 presents in the run), peak private 43.4 GB. Same env and frame presses on main
5ad98adbtonight: run 1 388 s in the cutscenes, 4.83 presents/s, 0 removals, exit 0x0, 2544 presents; run 2 device hung (0x887a0006) at 297.8 s after 238 s in the cutscenes at 4.64 presents/s, so main itself does not always get through. The title logs no XPackageMount line, so this run does not show whether it calls XPackageMountWithUiAsync at all: it checks for regressions, not the fix. Title binary = merge result + local scripted-press commits (input only) and two local log-only diagnostics, the same stack as the main runs.review: read the whole diff,
begin_with/payload_provider(xasync.rs) andXPackageMount. No blocking findings. 1) The fix is right:XPackageMountnow runs inside the work closure, so a nullXAsyncBlockor a terminated queue (whereXAsyncBeginfails andbegin_with_fixupsfrees the payload) no longer leaves a boxedMountbehind; the id is copied into an owned NUL-terminated buffer before the call, so the work no longer depends on the caller's string staying alive. 2) Behaviour change, as the earlier test report noted: anXPackageMountfailure (E_NOT_FOUNDfor another package id) now comes back throughXAsyncGetStatus/the result call instead of fromXPackageMountWithUiAsyncitself; that is the normal async pattern for this GDK API (XPackageMountWithUiAsync/XPackageMountWithUiResultin the GDK 261000 XPackage.h), so fine. 3) Not covered (and not made worse): a mount that completes but whose result the title never reads still keeps itsMountuntil the process ends. 4)LIVE_MOUNTSis test-only and global; no other test callsXPackageMount, so it does not race today, but a future test that mounts in parallel would make this one flaky.performance: none: one heap copy of the package id per call of a function a title calls once or twice; nothing on a per-frame path. Cutscene presents/s 3.86 vs 4.83 and 4.64 on main: the spread between runs of the same build is this large here (main run 2 device-hung, the other PR's runs tonight 4.24-4.82), and this diff does not run per frame; peak private 43.4 vs 43.5 GB.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0, debug (tests) / release (title run); Claude Code, Claude Opus 5.5
Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T03:21:59Z.
Review: COMMENTED
Review of
7124d1ef(code reading and the tests named below, not a merge-check) · no findingsIn short: the mount now happens inside the async work, so a call that never starts (null block) or whose queue is already terminated no longer leaves a
Mountbehind. The identifier is copied before the call returns, so the work does not read the title's string later.begin_withdrops the payload, and with it the copied identifier, whenXAsyncBeginrefuses the call.Result: no blockers found. From the code, nothing stands in the way of a merge. This is a review, not a merge-check: the suite and a title run are not covered here.
Measured (RTX 3080, Ryzen 9 7950X, merge of this head onto
main395405e4, debug)cargo test -p xcl --lib -- mount_with_ui_async_does_not_leak xgameruntime: 87 passed, 0 failed.main's body ofmount_with_ui_asyncput back,mount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_callfails ("Mount leaked on null XAsyncBlock", 1 live), so the test pins the fix.Note, not blocking: a mount that fails (an unknown package,
E_NOT_FOUND) used to fail the...Asynccall itself; it now returnsS_OKthere and the error comes out ofXAsyncGetStatus/ the result call. That is the usual shape of an async operation, but it is a change a title can see, and a line in the description would record it.Not checked: the whole suite and a title run on this head; a title that calls this function.
Review by Claude Code (Claude Fable 5.2), posted without a human check of each point. An automated PR review workflow is running at the request of the user.
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.