victory-hle: publish XAsyncComplete status before dropping call lookup #579
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!579
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-579"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@SalmanBarkat on GitHub · 2026-11-27 12:15 UTC · original
SalmanBarkat:fix/xasync-complete-release-order→a-publier· +68 −9 · 1 files · 3 commits · openSummary
complete_call()(crates/victory-hle/src/modules/xasync.rs) whererelease(block)removed theAsyncBlockfromCALLSbeforestatus.store(result, Ordering::Release)and*done = trueran. A concurrentXAsyncGetStatus(block, true)call could seecall(block) == None, skip waiting oncall.finished, and readE_PENDINGeven thoughwait = true.completing: AtomicBoolbeforecall.cleanup(block)runs soOP_CLEANUPexecutes outsidecall.doneandCALLSwhileblockstill cannot be freed, then lockcall.doneto publishsize/status, remove the entry fromCALLS, and wake waiters. Document thatOP_CLEANUPmust not synchronously re-enterXAsyncGetStatus(block, true)for the same block.status_waits_through_cleanupdeterministic regression test that holdsOP_CLEANUPopen whileXAsyncGetStatus(&raw mut block, true)waits and verifies bothE_ABORTcompletion and single-invocation cleanup.Verification
cargo clippy --workspace --all-targets --locked -- -D warnings(passed)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(passed)cargo test --locked -p victory-hle --lib modules::xasync(13 passed, 0 failed)cargo test --locked -p victory-hle --lib -- --skip only_loopback_is_reachable --skip a_kept_blob_past_the_link_limit_is_copied(161 passed, 0 failed, 2 ignored, 2 sandbox-excluded)cargo test -p xtask --locked(9 passed, 0 failed)@lvndrpup on GitHub · 2026-11-27 12:54 UTC · original · reviewed
Tested on an RTX 3060 Ti PC (Windows 11, debug build), base
4eb6cfdagainst headdf83f3c.4eb6cfddf83f3cget_status_wait_never_observes_pending_after_error_completion, copied onto baseXAsyncGetStatus(_, true)whileOP_CLEANUPrunsE_PENDING, 3 of 3E_ABORT, 3 of 3cargo test -p victory-hle --lib modules::xasynccargo clippy -p victory-hle --all-targets -- -D warnings, with and without--all-featuresThe race is real and this closes it. But the new test doesn't catch it on this machine: it passed on the base every time. The waiting thread almost always finds the call in
CALLSbefore the worker gets tocomplete_call, so the window between the removal and the status store is rarely hit. Holding the worker inside that window makes it deterministic. This fails on the base and passes here, in 0.2 s:On the code itself: the new order takes
CALLSwhile holding the call'sdone. Nothing takes them the other way round (call,is_current,releaseandXAsyncBeginholdCALLSonly briefly), so it can't deadlock. Theptr::eqcheck keeps a new call that the title began on the same block from being removed, andcleanedkeeps a laterreleasefrom runningOP_CLEANUPagain. It merges cleanly with #461, the other open PR onxasync.rsthat still merges witha-publier.@SalmanBarkat on GitHub · 2026-11-27 13:01 UTC · original
Thanks for the verification and the deterministic cleanup-window reproducer @lvndrpup. Replaced the probabilistic loop with
status_waits_through_cleanup(plus an assertion thatOP_CLEANUPexecutes once) inb94b57aand re-ran Clippy +victory-hletests cleanly.@gut0to on GitHub · 2026-11-27 13:05 UTC · original · reviewed
AI-assisted review. I traced the completion and cleanup lock ordering and left one reentrancy question inline.
@ -684,0 +691,4 @@// `block`) and without holding `call.done` or `CALLS`. `OP_CLEANUP`// must not synchronously re-enter `XAsyncGetStatus(block, true)` for// the same block, as its status is not published until cleanup ends.call.cleanup(block);@gut0to on GitHub · 2026-11-27 13:05 UTC · original
AI-assisted review: This invokes the provider's OP_CLEANUP callback while complete_call still holds call.done. If cleanup can re-enter XAsyncGetStatus(block, true), it will wait on the same mutex and deadlock before status is published. Could you document that reentrancy is forbidden or restructure the in-progress state so cleanup can run without holding the waiter mutex?
@SalmanBarkat on GitHub · 2026-11-27 13:12 UTC · original
Thanks for catching the lock scope @gust0to. Moved completion claiming onto
completing: AtomicBooline55aa74soOP_CLEANUPnow runs without holdingcall.doneorCALLS, and documented thatOP_CLEANUPmust not synchronously re-enterXAsyncGetStatus(block, true)on the same block.@lvndrpup on GitHub · 2026-11-27 14:09 UTC · original
Re-tested at
e55aa74on the same RTX 3060 Ti PC (Windows 11, debug build).e55aa74status_waits_through_cleanup, 30 runscargo test -p victory-hle --lib modules::xasync, 20 runscargo test -p victory-hle --lib, one runcargo clippy -p victory-hle --all-targets -- -D warnings, with and without--all-featuresTaking
doneafterOP_CLEANUPkeeps the fix. The call stays inCALLSuntil the status is stored, so a waiter that finds it still waits ondone, and one that doesn't find it reads the stored status.completingnow does the first-result-wins check thatdonedid.One case is unchanged. If
XAsyncCancellands while another thread's completion is inOP_CLEANUP, it returns at once, andXAsyncGetStatus(_, false)right after it readsE_PENDING. I checked with a probe like the one above, completing withS_OK, 0and cancelling during the cleanup:E_PENDINGon the base and one55aa74, 3 of 3 each. So it isn't a regression. Only a title that reads the status without waiting, right after a cancel that races a completion, would see it.@MamaLeVrai on GitHub · 2026-11-27 15:56 UTC · original
Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At
df83f3c:victory-hle163 passed, 0 failed, 2 ignored.AI-assisted (Claude Code); no game data.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.