XAsync: run a failed call's cleanup without the completion lock #114
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!114
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/114/head"
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?
@AndyLatimer on GitHub · 2026-11-24 00:38 UTC · original
AndyLatimer:fix/xasync-cleanup-unlocked→main· +46 −5 · 1 files · 2 commits · merged 2026-11-25 21:35 UTCXAsyncComplete(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
@DaviTostes on GitHub · 2026-11-24 01:12 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 00:17 UTC · original · edited 2026-11-25 10:20 UTC
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
@AndyLatimer on GitHub · 2026-11-25 09:42 UTC · original
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.