HLE/xasync: run a failed call's cleanup without the completion lock (port of upstream #114) #1330

Closed
github-bot wants to merge 1 commit from github-bot/gh-1330 into main AGit
Owner

@⁠CwWwWwW on GitHub · 2026-11-26 15:44 UTC · original
CwWwWwW:port/xasync-cleanup-lock → main · +52 −4 · 1 files · 1 commits · closed without merging

Problem

XAsyncComplete took the call's done lock and then ran the provider's cleanup while holding it - for a failing result, or a completion with no result size (crates/victory-hle/src/modules/xasync.rs). A provider whose cleanup waits for the thread that is completing the same call (or for a thread in XAsyncGetStatus) blocks on that lock while the completer waits for the cleanup: the title's async worker hangs permanently, and the whole game with it.

Upstream VIctory fixed this in commit 30a5202 (pull request #114, by Manuel Pérez); this is that fix ported to the fork.

Change

  • Call gets a claimed: AtomicBool; the first completion swaps it and does the work, a second completion returns (same 'first one wins' rule as before).
  • The cleanup runs before the status is published, with no lock held: a cleanup that waits for a status waiter can now finish and let the waiter proceed.
  • The status and result size are published, then the done lock is taken, the condition is set and waiters are woken.
  • XAsyncCancel checks the claim: a completion that is still running its cleanup is left alone instead of cancelling a call already ending.

Tests

  • New cleanup_runs_without_the_completion_lock: a provider's OP_CLEANUP checks whether the done lock is free. With the old completion it sees the lock held (SEEN=2, test fails); with this change it is free (SEEN=1, test passes) and the status is E_ABORT afterwards.
  • cargo test -p victory-hle --lib --locked: 104 passed, 0 failed.
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.
  • No game or GPU needed.

Coordination

Open PR #300 rewrites the same completion/cancel path for a different race (pending_with cancel use-after-free and the blocking XAsyncGetStatus wait). This fix is independent, but both edit the same lines: whichever lands second should be rebased. This branch is based on main; it does not include #300.

(CI note: the check job on main is currently red on the asset-policy violation; #1322 fixes that, after which this can be rebased.)

**@⁠CwWwWwW** on GitHub · 2026-11-26 15:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/1330) `CwWwWwW:port/xasync-cleanup-lock` → `main` · +52 −4 · 1 files · 1 commits · closed without merging ## Problem XAsyncComplete took the call's done lock and then ran the provider's cleanup while holding it - for a failing result, or a completion with no result size (crates/victory-hle/src/modules/xasync.rs). A provider whose cleanup waits for the thread that is completing the same call (or for a thread in XAsyncGetStatus) blocks on that lock while the completer waits for the cleanup: the title's async worker hangs permanently, and the whole game with it. Upstream VIctory fixed this in commit 30a5202 (pull request #114, by Manuel Pérez); this is that fix ported to the fork. ## Change - `Call` gets a `claimed: AtomicBool`; the first completion swaps it and does the work, a second completion returns (same 'first one wins' rule as before). - The cleanup runs before the status is published, with no lock held: a cleanup that waits for a status waiter can now finish and let the waiter proceed. - The status and result size are published, then the done lock is taken, the condition is set and waiters are woken. - XAsyncCancel checks the claim: a completion that is still running its cleanup is left alone instead of cancelling a call already ending. ## Tests - New cleanup_runs_without_the_completion_lock: a provider's OP_CLEANUP checks whether the done lock is free. With the old completion it sees the lock held (SEEN=2, test fails); with this change it is free (SEEN=1, test passes) and the status is E_ABORT afterwards. - cargo test -p victory-hle --lib --locked: **104 passed, 0 failed**. - cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean. - No game or GPU needed. ## Coordination Open PR #300 rewrites the same completion/cancel path for a different race (pending_with cancel use-after-free and the blocking XAsyncGetStatus wait). This fix is independent, but both edit the same lines: whichever lands second should be rebased. This branch is based on main; it does not include #300. (CI note: the check job on main is currently red on the asset-policy violation; #1322 fixes that, after which this can be rebased.)
Ported from upstream VIctory commit 30a5202 (pull request #114, Manuel
Pérez): XAsyncComplete held the call's done lock and then ran the
provider's cleanup inside it (for a failing result or a completion with no
result size). A provider whose cleanup waits for the thread that is
completing the same call - or for a thread in XAsyncGetStatus - then
blocked on that lock while the completer waited for the cleanup: the
title's async worker hung for good.

The first completion now claims the call with an atomic flag and runs the
cleanup before publishing the status, with no lock held; a second
completion and XAsyncCancel see the claim and leave the call alone. The
status is published and the done lock taken only after the cleanup, so a
waiter in XAsyncGetStatus wakes when the call is really over.

Test: cleanup_runs_without_the_completion_lock (a provider's OP_CLEANUP
checks that the done lock is free; it sees the lock held with the old
code and free with this one). cargo test -p victory-hle --lib: 104
passed, 0 failed; cargo clippy -p victory-hle --all-targets -- -D
warnings: clean.

Note: open PR #300 rewrites the same completion path for a different race
(pending_with cancel use-after-free and the blocking XAsyncGetStatus
wait); this change is independent there, but the two touch the same lines
and whichever lands second must be rebased.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:46:43 +00:00
github-bot closed this pull request 2026-11-26 15:52:05 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.