XAsync: run a failed call's cleanup without the completion lock #114

Manually merged
github merged 2 commits from gh-pr/114/head into gh-pr/114/base 2026-11-26 03:50:44 +00:00
Owner

@⁠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 UTC

XAsyncComplete (crates/victory-hle/src/modules/xasync.rs) took the call's done lock and held it while release ran the title provider's OP_CLEANUP, for a failed call or one with no result. The "Unlocked before the provider runs" note in release only covers CALLS.

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 on done. The cancel path (XAsyncCancel → provider OP_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. Then done is set and finished notified for XAsyncGetStatus(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's done lock. 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 --check reports nothing in the changed lines. The other hunks in this file already exist on main.
  • Tested with a synthetic unit test only (not run against a title).

🤖 Generated with Claude Code

**@⁠AndyLatimer** on GitHub · 2026-11-24 00:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/114) `AndyLatimer:fix/xasync-cleanup-unlocked` → `main` · +46 −5 · 1 files · 2 commits · merged 2026-11-25 21:35 UTC `XAsyncComplete` (`crates/victory-hle/src/modules/xasync.rs`) took the call's `done` lock and held it while `release` ran the title provider's `OP_CLEANUP`, for a failed call or one with no result. The "Unlocked before the provider runs" note in `release` only covers `CALLS`. 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 on `done`. The cancel path (`XAsyncCancel` → provider `OP_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. Then `done` is set and `finished` notified for `XAsyncGetStatus(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's `done` lock. 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 --check` reports nothing in the changed lines. The other hunks in this file already exist on `main`. - Tested with a synthetic unit test only (not run against a title). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XAsyncComplete held the call's `done` lock while the title's provider
ran OP_CLEANUP. A cleanup that waits for a worker thread which is itself
completing the same call (it took the call before the cleanup removed
it) deadlocked: the worker blocks on `done`. The first completion now
claims the call with an atomic flag and runs unlocked; the status is
still published after the cleanup, while the block is valid, and `done`
is set only for the waiters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On `main` the completion moved into `complete_call`; the claim goes with
it. `XAsyncCancel` (new on `main`) left a call alone once `done` was set;
`done` is now set after the cleanup, so it checks the claim instead: a
completion running its cleanup is not canceled under it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:42 +00:00
github manually merged commit 944df1bd0a into gh-pr/114/base 2026-11-26 03:50:44 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:12 UTC · original

Tested 0b729de: pass (no regression).

  • Tested the Windows build under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle: 81 passed, 1 failed, including the 1 test this PR adds.
  • The one failure is modules::net::tests::only_loopback_is_reachable (Wine lacks WSAConnectByList, as in #118), not this PR.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/114#issuecomment-7118860681) Tested `0b729de`: **pass (no regression)**. - Tested the Windows build under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), `cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle`: **81 passed, 1 failed**, including the 1 test this PR adds. - The one failure is `modules::net::tests::only_loopback_is_reachable` (Wine lacks `WSAConnectByList`, as in #118), not this PR. No game data used.
Author
Owner

@⁠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. In crates/victory-hle/src/modules/xasync.rs, complete_call claims the call with a new claimed: AtomicBool and no longer holds done. So release (the provider's OP_CLEANUP) runs with no lock held. done is set and finished notified only after the status is published, so XAsyncGetStatus(wait) still waits for the status. XAsyncCancel now checks claimed, so a call whose completion is already running is not sent OP_CANCEL. XAsyncBegin still checks done.

On main, the cleanup does run under done, so the deadlock it describes is real. The new test cleanup_runs_without_the_completion_lock checks exactly that. One behaviour change: a second completer, or XAsyncCancel, now returns at once instead of blocking until the first completion finishes. That looks acceptable. CI passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/114#issuecomment-7148350633) · edited 2026-11-25 10:20 UTC <!-- victory-triage v1 head=944df1bd0a61c99b87aa91d2bc60ff5a817b1a10 verdict=merge-candidate at=2026-11-25T10:20:29Z --> Automated triage for the maintainers. **Merge candidate.** Now merges cleanly into `main`. In `crates/victory-hle/src/modules/xasync.rs`, `complete_call` claims the call with a new `claimed: AtomicBool` and no longer holds `done`. So `release` (the provider's `OP_CLEANUP`) runs with no lock held. `done` is set and `finished` notified only after the status is published, so `XAsyncGetStatus(wait)` still waits for the status. `XAsyncCancel` now checks `claimed`, so a call whose completion is already running is not sent `OP_CANCEL`. `XAsyncBegin` still checks `done`. On `main`, the cleanup does run under `done`, so the deadlock it describes is real. The new test `cleanup_runs_without_the_completion_lock` checks exactly that. One behaviour change: a second completer, or `XAsyncCancel`, now returns at once instead of blocking until the first completion finishes. That looks acceptable. CI passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-25 09:42 UTC · original

Merged main (940d32f) at 944df1b.

  • On main the completion moved into complete_call, and the claim moved with it. The bug is still on main: release (the provider's OP_CLEANUP) runs while done is held.
  • XAsyncCancel (new on main, from #1098) left a call alone once done was set. With this PR, done is set only after the cleanup. If XAsyncCancel still checked done, it could send OP_CANCEL to a call whose completion is already running. So it now checks the claim: a call that a completion has claimed is left alone. XAsyncBegin keeps checking done: a call still mid-completion is not over, and its block is still in use.

Checks (Windows 11, NVIDIA, Rust 1.98.1):

  • clippy -D warnings, default and --all-features: clean.
  • xasync tests: 13 passed.
  • cargo test --workspace --locked --no-fail-fast: 697 passed, 5 failed. The 5 are the ones #1744 lists (in victory-gpu and victory-shader, which this PR doesn't touch).

The earlier test reports were on 0b729de.

**@⁠AndyLatimer** on GitHub · 2026-11-25 09:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/114#issuecomment-7158684023) Merged `main` (`940d32f`) at `944df1b`. - On `main` the completion moved into `complete_call`, and the claim moved with it. The bug is still on `main`: `release` (the provider's `OP_CLEANUP`) runs while `done` is held. - `XAsyncCancel` (new on `main`, from #1098) left a call alone once `done` was set. With this PR, `done` is set only after the cleanup. If `XAsyncCancel` still checked `done`, it could send `OP_CANCEL` to a call whose completion is already running. So it now checks the claim: a call that a completion has claimed is left alone. `XAsyncBegin` keeps checking `done`: a call still mid-completion is not over, and its block is still in use. **Checks** (Windows 11, NVIDIA, Rust 1.98.1): - clippy `-D warnings`, default and `--all-features`: clean. - `xasync` tests: 13 passed. - `cargo test --workspace --locked --no-fail-fast`: 697 passed, 5 failed. The 5 are the ones #1744 lists (in `victory-gpu` and `victory-shader`, which this PR doesn't touch). The earlier test reports were on `0b729de`.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!114
No description provided.