XAsync: a wait on a failed call during its cleanup waits for the status #374

Open
marquezinii wants to merge 1 commit from upstream-pr/374 into main
marquezinii commented 2026-11-24 02:43:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T02:43:15Z.


A failed (or zero-size) call is removed from CALLS and has its provider's cleanup run in XAsyncComplete before its status is stored. A thread calling XAsyncGetStatus(block, true) in that window finds no call, so it does not wait, and reads the status that is still E_PENDING. The docs say a wait returns only once the call "either completes or is canceled".

This keeps the order (cleanup, then the status), which #114 also relies on, and fixes the waiter instead: when there is no call for the block and its status is still pending, it waits on a condition variable that XAsyncComplete notifies after it publishes a status. The check and the wait are done under the same lock the notifier takes after the store, so a wakeup cannot be lost.

Tested with a new test: a provider whose cleanup starts a thread that waits on the block, then gives it 100 ms to find the call gone. Before the change that thread gets E_PENDING (3 of 3 runs); now it gets E_ABORT (5 of 5 runs). cargo test -p victory-hle passes and clippy reports nothing new. Not tried in a title run.

The change sits next to the lines #114 edits in XAsyncComplete, so whichever lands second may need a trivial rebase.

https://learn.microsoft.com/gaming/gdk/docs/reference/system/xasync/functions/xasyncgetstatus

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573424281 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/374). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T02:43:15Z. --- A failed (or zero-size) call is removed from `CALLS` and has its provider's cleanup run in `XAsyncComplete` before its status is stored. A thread calling `XAsyncGetStatus(block, true)` in that window finds no call, so it does not wait, and reads the status that is still `E_PENDING`. The docs say a wait returns only once the call "either completes or is canceled". This keeps the order (cleanup, then the status), which #114 also relies on, and fixes the waiter instead: when there is no call for the block and its status is still pending, it waits on a condition variable that `XAsyncComplete` notifies after it publishes a status. The check and the wait are done under the same lock the notifier takes after the store, so a wakeup cannot be lost. Tested with a new test: a provider whose cleanup starts a thread that waits on the block, then gives it 100 ms to find the call gone. Before the change that thread gets `E_PENDING` (3 of 3 runs); now it gets `E_ABORT` (5 of 5 runs). `cargo test -p victory-hle` passes and clippy reports nothing new. Not tried in a title run. The change sits next to the lines #114 edits in `XAsyncComplete`, so whichever lands second may need a trivial rebase. https://learn.microsoft.com/gaming/gdk/docs/reference/system/xasync/functions/xasyncgetstatus
jeremygold02 commented 2026-11-24 06:55:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:09:43Z.


Thanks @marquezinii for this waiter-race fix. I tested head 9d6bc0c7c6811c012f39501aa297ddd261d3870f with:

cargo test --locked -p victory-hle --lib a_wait_during_a_failed_calls_cleanup_sees_the_failure -- --test-threads=1

Result: 1 passed, 0 failed (86 filtered out). The regression test starts a waiter during failed-call cleanup and verifies XAsyncGetStatus observes the published E_ABORT instead of returning while the status is still pending. This is a synthetic concurrency test; I did not run a title.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121763218 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/374#issuecomment-7121763218). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:09:43Z. --- Thanks @marquezinii for this waiter-race fix. I tested head `9d6bc0c7c6811c012f39501aa297ddd261d3870f` with: ``` cargo test --locked -p victory-hle --lib a_wait_during_a_failed_calls_cleanup_sees_the_failure -- --test-threads=1 ``` Result: 1 passed, 0 failed (86 filtered out). The regression test starts a waiter during failed-call cleanup and verifies `XAsyncGetStatus` observes the published `E_ABORT` instead of returning while the status is still pending. This is a synthetic concurrency test; I did not run a title.
Makto94 commented 2026-11-24 20:03:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Makto94 on 2026-11-24T19:32:42Z.


CI evidence that this flake turns unrelated PRs red:

panicked at crates\victory-hle\src\modules\xasync.rs:1205:9:
assertion `left == right` failed
  left: -2147483638   (E_PENDING)
 right: -2147467260   (E_ABORT)

The status is read while the call is still pending. #566 does not touch victory-hle. This PR makes the wait wait for the status, which is the race shown here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142250084 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/374#issuecomment-7142250084). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-24T19:32:42Z. --- CI evidence that this flake turns unrelated PRs red: - Run https://github.com/Marvisak/VIctory/actions/runs/45363471943 (branch `shader/per-lane-phi`, PR #566, a shader-only change, commit e09dbb6) failed on `modules::xasync::tests::run_returns_the_work_result`: ``` panicked at crates\victory-hle\src\modules\xasync.rs:1205:9: assertion `left == right` failed left: -2147483638 (E_PENDING) right: -2147467260 (E_ABORT) ``` The status is read while the call is still pending. #566 does not touch `victory-hle`. This PR makes the wait wait for the status, which is the race shown here.
Marvisak commented 2026-11-25 01:07:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:15:44Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/src/modules/xasync.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148323625 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/374#issuecomment-7148323625). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:15:44Z. --- <!-- victory-triage v1 head=9d6bc0c7c6811c012f39501aa297ddd261d3870f verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-hle/src/modules/xasync.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/374:upstream-pr/374'
git switch 'upstream-pr/374'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/374'
git switch 'upstream-pr/374'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/374'
git switch 'upstream-pr/374'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/374'
git switch 'main'
git merge --squash 'upstream-pr/374'
git switch 'main'
git merge --ff-only 'upstream-pr/374'
git switch 'main'
git merge 'upstream-pr/374'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!374
No description provided.