XAsync: run a failed call's cleanup without the completion lock #114
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/114"
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 Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-24T00:38:25Z.
XAsyncComplete(crates/victory-hle/src/modules/xasync.rs) took the call'sdonelock and held it whilereleaseran the title provider'sOP_CLEANUP, for a failed call or one with no result. The "Unlocked before the provider runs" note inreleaseonly coversCALLS.A cleanup that waits for another thread can deadlock. For example, it joins a worker thread that is itself completing the same call: the worker took the
Arc<Call>before the cleanup removed it, and now blocks ondone. The cancel path (XAsyncCancel→ providerOP_CANCEL→XAsyncComplete(E_ABORT)) racing a worker's own completion is the plausible trigger.Now the first completion claims the call with an atomic flag (
claimed); later completions return at once, as before. It runs the cleanup with no lock held. The order is unchanged: the cleanup still runs before the status is published, while the block is guaranteed valid. Thendoneis set andfinishednotified forXAsyncGetStatus(wait), which still waits for the published status.Testing
cargo test --workspace: 225 passed, 3 ignored (need external files). Includes 1 new test,cleanup_runs_without_the_completion_lock: its provider's cleanup tries the call'sdonelock. It fails on the old code (checked by putting the old lines back), where the lock is held.cargo clippy --workspace --all-targets: 0 warnings.cargo xtask policy: pass (148 files).rustfmt --checkreports nothing in the changed lines. The other hunks in this file already exist onmain.🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:12:04Z.
Tested
0b729de: pass (no regression).cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle: 81 passed, 1 failed, including the 1 test this PR adds.modules::net::tests::only_loopback_is_reachable(Wine lacksWSAConnectByList, as in #118), not this PR.No game data used.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:51:00Z.
Review: APPROVED
Tested
0b729deon Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (225 passed, 0 failed; older base), includingcleanup_runs_without_the_completion_lock.donewas held acrossrelease, which runs the provider'sOP_CLEANUP, and a cleanup that joins a worker still inXAsyncCompletefor the same call would block on that lock forever.claimedkeeps "first completion wins" and drops the lock from the cleanup. The order is unchanged: cleanup, thendone = true, thennotify_all, soXAsyncGetStatus(wait = true)still returns only after the status is published.XAsyncCompletedon't rely on its return timing, and it is exactly what removes the deadlock.No issues found.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:17:14Z.
Automated triage for the maintainers.
Merge candidate. Now merges cleanly into
main. Incrates/victory-hle/src/modules/xasync.rs,complete_callclaims the call with a newclaimed: AtomicBooland no longer holdsdone. Sorelease(the provider'sOP_CLEANUP) runs with no lock held.doneis set andfinishednotified only after the status is published, soXAsyncGetStatus(wait)still waits for the status.XAsyncCancelnow checksclaimed, so a call whose completion is already running is not sentOP_CANCEL.XAsyncBeginstill checksdone.On
main, the cleanup does run underdone, so the deadlock it describes is real. The new testcleanup_runs_without_the_completion_lockchecks exactly that. One behaviour change: a second completer, orXAsyncCancel, now returns at once instead of blocking until the first completion finishes. That looks acceptable. CI passes.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-25T09:42:03Z.
Merged
main(940d32f) at944df1b.mainthe completion moved intocomplete_call, and the claim moved with it. The bug is still onmain:release(the provider'sOP_CLEANUP) runs whiledoneis held.XAsyncCancel(new onmain, from #1098) left a call alone oncedonewas set. With this PR,doneis set only after the cleanup. IfXAsyncCancelstill checkeddone, it could sendOP_CANCELto a call whose completion is already running. So it now checks the claim: a call that a completion has claimed is left alone.XAsyncBeginkeeps checkingdone: a call still mid-completion is not over, and its block is still in use.Checks (Windows 11, NVIDIA, Rust 1.98.1):
-D warnings, default and--all-features: clean.xasynctests: 13 passed.cargo test --workspace --locked --no-fail-fast: 697 passed, 5 failed. The 5 are the ones #1744 lists (invictory-gpuandvictory-shader, which this PR doesn't touch).The earlier test reports were on
0b729de.