XAsync: publish the final status before removing a completed call #1205

Manually merged
github merged 1 commit from github-bot/gh-1205 into main 2026-11-29 08:21:55 +00:00 AGit
Owner

@⁠Jineggegg on GitHub · 2026-11-28 15:31 UTC · original
Jineggegg:xasync-publish-before-remove → main · +96 −24 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC

What this changes

An error or zero-size completion removed its call from the registry before provider cleanup ran. A blocking status query arriving during cleanup could miss the call and read E_PENDING from the block instead of the work's result.

  • The call stays registered while cleanup runs unlocked, and is removed only after its status is published, both under the registry lock.
  • done becomes the published result (Mutex<Option<HRESULT>>), so a waiting query returns the captured result even if the block is reused afterwards. XAsyncGetStatus(wait=true) now waits on the condition variable until that result exists instead of re-reading the block.
  • While a call is completing, its provider can no longer do new work on it (pending_call replaces is_current); waiters can still find it.

Adapted from Jineggegg/VIctory round 1 item 3 (commit e071177). One adaptation to current main: upstream has no claimed flag — its complete_call guard is the done lock — so the guard now reads is_some() after done became an Option, and no claimed flag is added back. Because cleanup runs without the done lock, an error/zero-size completion records its result first (that is the guard against a second completion); a successful completion still publishes before recording, as before. The regression test is unchanged in shape: a provider cleanup paused on a barrier, a non-waiting poll that must read E_PENDING, and a waiting query that must return E_ABORT.

Testing

  • cargo check -p victory-hle is clean.
  • cargo test -p victory-hle --lib xasync: all 15 tests pass, including the new status_waits_for_cleanup_to_publish_the_result (run 5 times) and the existing cancellation tests.

Notes on nearby open PRs

  • #887 (a wait ends after the completion callback returns): still open. It changes complete_call to take &Arc<Call> and reworks the wait in XAsyncGetStatus, so whichever lands second needs a rebase in that function.
  • #868 (a canceled call is completed by its provider): still open. It touches XAsyncCancel and the completion call sites, but not the done flag itself.
  • #898 (cleanup waits for provider calls under way, bounded threads): still open. It touches the same functions mostly as context.
  • #915 (GPU and async internals): still open. Its xasync.rs changes are unrelated to this race.
**@⁠Jineggegg** on GitHub · 2026-11-28 15:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1205) `Jineggegg:xasync-publish-before-remove` → `main` · +96 −24 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC ## What this changes An error or zero-size completion removed its call from the registry before provider cleanup ran. A blocking status query arriving during cleanup could miss the call and read `E_PENDING` from the block instead of the work's result. - The call stays registered while cleanup runs unlocked, and is removed only after its status is published, both under the registry lock. - `done` becomes the published result (`Mutex<Option<HRESULT>>`), so a waiting query returns the captured result even if the block is reused afterwards. `XAsyncGetStatus(wait=true)` now waits on the condition variable until that result exists instead of re-reading the block. - While a call is completing, its provider can no longer do new work on it (`pending_call` replaces `is_current`); waiters can still find it. Adapted from Jineggegg/VIctory round 1 item 3 (commit `e071177`). One adaptation to current `main`: upstream has no `claimed` flag — its `complete_call` guard is the `done` lock — so the guard now reads `is_some()` after `done` became an `Option`, and no `claimed` flag is added back. Because cleanup runs without the `done` lock, an error/zero-size completion records its result first (that is the guard against a second completion); a successful completion still publishes before recording, as before. The regression test is unchanged in shape: a provider cleanup paused on a barrier, a non-waiting poll that must read `E_PENDING`, and a waiting query that must return `E_ABORT`. ## Testing - `cargo check -p victory-hle` is clean. - `cargo test -p victory-hle --lib xasync`: all 15 tests pass, including the new `status_waits_for_cleanup_to_publish_the_result` (run 5 times) and the existing cancellation tests. ## Notes on nearby open PRs - #887 (a wait ends after the completion callback returns): still open. It changes `complete_call` to take `&Arc<Call>` and reworks the wait in `XAsyncGetStatus`, so whichever lands second needs a rebase in that function. - #868 (a canceled call is completed by its provider): still open. It touches `XAsyncCancel` and the completion call sites, but not the `done` flag itself. - #898 (cleanup waits for provider calls under way, bounded threads): still open. It touches the same functions mostly as context. - #915 (GPU and async internals): still open. Its `xasync.rs` changes are unrelated to this race.
An error or zero-size completion removed its call before provider cleanup. A blocking status query could miss the call during cleanup and read E_PENDING instead of the work result.

Keep the claimed call available to waiters during unlocked cleanup, exclude it from new work, then publish the status and remove the entry under the registry lock. Return the captured call result to existing waiters even if the block is reused. Exercise the race deterministically with a paused cleanup.

Adapted from Jineggegg/VIctory round 1 item 3 (e071177) to current main.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 15:32:56 +00:00
Author
Owner

@⁠illuminatedfellow on GitHub · 2026-11-28 18:04 UTC · original

Tested on Linux (xasync.rs built alone with a stub for xgameruntime): all 15 xasync tests pass, and status_waits_for_cleanup_to_publish_the_result fails on main (E_PENDING instead of E_ABORT) and passes here; 60 runs without a failure.

One thing for whichever of this and #898 merges second: they merge without a conflict, but complete_call here calls call.provider(OP_CLEANUP, …) directly, while #898 routes cleanup through Call::cleanup, which waits for a DoWork or Cancel still running. Merged as they are, #898's cleanup_waits_for_work_under_way fails every time. Changing that line to call.cleanup(block) makes all 23 tests of both pass (80 runs, clippy clean).

**@⁠illuminatedfellow** on GitHub · 2026-11-28 18:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1205#issuecomment-7243505750) Tested on Linux (`xasync.rs` built alone with a stub for `xgameruntime`): all 15 xasync tests pass, and `status_waits_for_cleanup_to_publish_the_result` fails on `main` (E_PENDING instead of E_ABORT) and passes here; 60 runs without a failure. One thing for whichever of this and #898 merges second: they merge without a conflict, but `complete_call` here calls `call.provider(OP_CLEANUP, …)` directly, while #898 routes cleanup through `Call::cleanup`, which waits for a `DoWork` or `Cancel` still running. Merged as they are, #898's `cleanup_waits_for_work_under_way` fails every time. Changing that line to `call.cleanup(block)` makes all 23 tests of both pass (80 runs, clippy clean).
github manually merged commit 5cda61d6be into main 2026-11-29 08:21:55 +00:00
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/trustno1-coder--VIctory-NVIDIA!1205
No description provided.