HLE: keep async status waits attached through provider cleanup #3195

Open
github-bot wants to merge 1 commit from github-bot/gh-3195 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 11:56 UTC · original
andrewpozdnakov7-jpg:codex2/xasync-wait-cleanup → main · +76 −3 · 1 files · 1 commits · open

Problem

XAsyncGetStatus(block, true) can return E_PENDING for a call that is already inside provider cleanup. Completion removes the call from the registry before cleanup, then publishes the final status when cleanup returns. A waiter arriving in that interval finds nothing to wait on. XAsyncGetStatus contract

Keep the call registered while the provider cleans up. Remove it and publish its final status under the registry lock. Cleanup still runs before status publication and outside both locks, as in #114.

Verification

The same synthetic provider pauses inside cleanup on main 63bcca43 and on this branch. Each trial includes a zero-payload success and a cancellation.

Call Main while cleanup is paused Patched after cleanup returns
Zero-payload success E_PENDING returned early S_OK
Cancellation E_PENDING returned early E_ABORT

A nonblocking poll reports E_PENDING while cleanup is paused in both builds. Main failed 10/10 trials. The patch passed 10/10, with both outcomes checked in every trial. Full HLE library tests passed 153/153 in both configurations, including the cleanup-lock regression from #114. Strict HLE Clippy and the repository asset policy passed.

cargo test --locked -p victory-hle --lib modules::xasync::tests::waiting_status_follows_payload_free_cleanup -- --exact --nocapture

Coordination claim

AI-assisted with Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 11:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/3195) `andrewpozdnakov7-jpg:codex2/xasync-wait-cleanup` → `main` · +76 −3 · 1 files · 1 commits · open ## Problem `XAsyncGetStatus(block, true)` can return `E_PENDING` for a call that is already inside provider cleanup. Completion removes the call from the registry before cleanup, then publishes the final status when cleanup returns. A waiter arriving in that interval finds nothing to wait on. [XAsyncGetStatus contract](https://learn.microsoft.com/en-us/xbox/gdk/docs/reference/system/xasync/functions/xasyncgetstatus) Keep the call registered while the provider cleans up. Remove it and publish its final status under the registry lock. Cleanup still runs before status publication and outside both locks, as in #114. ## Verification The same synthetic provider pauses inside cleanup on main `63bcca43` and on this branch. Each trial includes a zero-payload success and a cancellation. | Call | Main while cleanup is paused | Patched after cleanup returns | | --- | --- | --- | | Zero-payload success | `E_PENDING` returned early | `S_OK` | | Cancellation | `E_PENDING` returned early | `E_ABORT` | A nonblocking poll reports `E_PENDING` while cleanup is paused in both builds. Main failed 10/10 trials. The patch passed 10/10, with both outcomes checked in every trial. Full HLE library tests passed 153/153 in both configurations, including the cleanup-lock regression from #114. Strict HLE Clippy and the repository asset policy passed. ```powershell cargo test --locked -p victory-hle --lib modules::xasync::tests::waiting_status_follows_payload_free_cleanup -- --exact --nocapture ``` [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) AI-assisted with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:57:06 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 12:12 UTC · original

Independent local verification of head c079fab on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-hle --lib -- --exact modules::xasync::tests::waiting_status_follows_payload_free_cleanup — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

CPU-only synthetic thread/payload scenario; no D3D12 device or game data used. Worktree-local CARGO_TARGET_DIR. AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-26 12:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/3195#issuecomment-7191694255) Independent local verification of head `c079fab` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-hle --lib -- --exact modules::xasync::tests::waiting_status_follows_payload_free_cleanup` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. CPU-only synthetic thread/payload scenario; no D3D12 device or game data used. Worktree-local `CARGO_TARGET_DIR`. AI-assisted (Hy4 flash).
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 12:33 UTC · original · reviewed

The race is real and the fix closes it. I read it against release, call, XAsyncBegin and XAsyncGetStatus on main:

  • The window: on main, release removes the call from CALLS before OP_CLEANUP, and the status is published only after cleanup returns. A blocking XAsyncGetStatus in between finds no call and returns the still-E_PENDING status.
  • The fix: the call now stays registered through cleanup. Removing it and storing size/status happen under the CALLS lock, so a waiter either finds the call and blocks on done, or finds it gone and reads the final status. Cleanup still runs with no lock held, so the #114 case (cleanup_runs_without_the_completion_lock) keeps working.
  • Reuse of the block during cleanup: XAsyncBegin on the same block is rejected while done is still false, so no new call can be filed at that address before the unconditional calls.remove(&(block as usize)). The removal can't drop someone else's call.

Two small points:

1. A new constraint on providers, worth writing down. Since the call is now registered while OP_CLEANUP runs, a provider whose cleanup calls XAsyncGetStatus(block, true) on its own block would now block forever, because done is only set after cleanup returns. On main, it got E_PENDING straight away. The in-tree cleanups only drop their boxed state (finished_with, and the one at L856), so nothing hits this today. A line in the comment would keep a future provider from tripping on it, e.g. "cleanup must not wait on its own block". If you want the removal to be robust on its own rather than relying on XAsyncBegin's done check, you could also guard it with Arc::ptr_eq, the way is_current does.

2. Nit: the eprintln! in the test. It looks like it was left over from investigating, since the assert_eq! on outcomes already prints all four values when it fails. Also, the 250 ms recv_timeout can only make a slow runner pass falsely (an early return that arrives late), never fail falsely, so the test shouldn't be flaky. 👍

**@⁠AurumCarlos** on GitHub · 2026-11-26 12:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3195#pullrequestreview-6074185485) · **reviewed** The race is real and the fix closes it. I read it against `release`, `call`, `XAsyncBegin` and `XAsyncGetStatus` on `main`: - **The window**: on `main`, `release` removes the call from `CALLS` *before* `OP_CLEANUP`, and the status is published only after cleanup returns. A blocking `XAsyncGetStatus` in between finds no call and returns the still-`E_PENDING` status. - **The fix**: the call now stays registered through cleanup. Removing it and storing `size`/`status` happen under the `CALLS` lock, so a waiter either finds the call and blocks on `done`, or finds it gone and reads the final status. Cleanup still runs with no lock held, so the #114 case (`cleanup_runs_without_the_completion_lock`) keeps working. - **Reuse of the block during cleanup**: `XAsyncBegin` on the same block is rejected while `done` is still false, so no new call can be filed at that address before the unconditional `calls.remove(&(block as usize))`. The removal can't drop someone else's call. Two small points: **1. A new constraint on providers, worth writing down.** Since the call is now registered while `OP_CLEANUP` runs, a provider whose cleanup calls `XAsyncGetStatus(block, true)` on its own block would now block forever, because `done` is only set after cleanup returns. On `main`, it got `E_PENDING` straight away. The in-tree cleanups only drop their boxed state (`finished_with`, and the one at L856), so nothing hits this today. A line in the comment would keep a future provider from tripping on it, e.g. "cleanup must not wait on its own block". If you want the removal to be robust on its own rather than relying on `XAsyncBegin`'s `done` check, you could also guard it with `Arc::ptr_eq`, the way `is_current` does. **2. Nit: the `eprintln!` in the test.** It looks like it was left over from investigating, since the `assert_eq!` on `outcomes` already prints all four values when it fails. Also, the 250 ms `recv_timeout` can only make a slow runner pass falsely (an early return that arrives late), never fail falsely, so the test shouldn't be flaky. 👍
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3195/head:github-bot/gh-3195'
git switch 'github-bot/gh-3195'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3195'
git switch 'github-bot/gh-3195'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3195'
git switch 'github-bot/gh-3195'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3195'
git switch 'main'
git merge --squash 'github-bot/gh-3195'
git switch 'main'
git merge --ff-only 'github-bot/gh-3195'
git switch 'main'
git merge 'github-bot/gh-3195'
git push origin 'main'
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!3195
No description provided.