HLE: retain pending_with state across cancellation and prevent stale block completions #2520
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2522"
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?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:16:36Z.
Problem
xasync::pending_withstored its shared closure/result buffer in a rawBox<Data>freed inOP_CLEANUP, while spawning a background thread that held the raw pointer and completed the call viaXAsyncComplete(block, ...).If the caller cancels the block with
XAsyncCancelbefore the worker thread finishes:XAsyncCancelimmediately triggersOP_CLEANUP, freeingDatawhile the worker still holds the pointer — causing a heap use-after-free when the worker writes its result bytes.XAsyncComplete(block, ...)matches by block address rather than the originalArc<Call>, so if the caller reuses the block for a new async call after cancellation, the late worker completes the unrelated new call.Fix
Datain anArc<Data>soOP_BEGINclones a strong reference for the worker thread, keeping the state alive even ifOP_CLEANUPruns on cancellation.Arc<Call>duringOP_BEGINand complete viacomplete_callonly whenis_current(¤t, block)is still true.Testing
canceled_pending_with_keeps_state_alive_and_leaves_reused_block_aloneincrates/victory-hle/src/modules/xasync.rs.cargo test -p xtask --lockedpasses asset policy.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:52:43Z.
Automated triage for the maintainers.
Merge candidate. Thanks for the rebase.
pending_withincrates/victory-hle/src/modules/xasync.rsnow keeps its state in anArc.OP_BEGINhands the worker its own strong reference, so a cancel that runsOP_CLEANUPfirst can no longer free the state under the worker. The worker completes through theArc<Call>it captured (is_current+complete_call), notXAsyncCompleteby block address, so a late worker leaves a reused block's new call alone. That fitsmain'sXAsyncCancel→complete_call(E_ABORT)→releasepath. The new test covers both cancel-then-reuse cases.CI:
checkpassing; merges cleanly.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:56:00Z.
Rebased cleanly onto current
main(63bcca4, resolving the test-append conflict with30a5202).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:34:01Z.
Review: CHANGES_REQUESTED
Verified
76f4d989locally on Windows 11 x64 (git merge-treeonto63bcca43is clean):cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean (9.46s).cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 0 failed (0.56s).cargo test -p victory-hle --locked: 155 passed, 0 failed (153lib including all 14modules::xasync::tests+1fidelityfx +1no_dll_planting,4.53s).The
Arc<Data>worker reference fixes the lifetime onceOP_BEGINhas run, but two startup race conditions remain betweenXAsyncBegin(xasync.rs:604-606) andOP_BEGIN(xasync.rs:855-870):xasync.rs:558-563, 604-606, 855-865):XAsyncBeginpublishescallintoCALLS(:604) before callingprovider(OP_BEGIN)(:606). IfXAsyncCancelruns in that window,releaseinvokesOP_CLEANUPand drops the soleArc<Data>reference beforeOP_BEGINcallsArc::increment_strong_count(state).Callidentity race (xasync.rs:604-606, 866-883): becauseOP_BEGINre-looks upcall(data.block)by raw block address, a cancel + block-reuse in that startup window can causecurrentto bind to the newCallinstead of the canceled one.Please keep the provider context alive across
OP_BEGINstartup and bind the worker directly to the initiatingArc<Call>(and synchronize on the old worker's completion checkpoint instead ofsleep(50ms)in the reuse test).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:01:29Z.
Review: APPROVED
Reviewed
367cd009and confirmed both startup/reuse races from the previous round are cleanly fixed:pending_with_handleclonesworker_statebefore publishing the call throughregister_call, binds the worker thread directly to itsArc<Call>viacomplete_callinstead of re-looking up the block address inCALLS, and joins both worker handles deterministically incanceled_pending_with_keeps_state_alive_and_leaves_reused_block_alone.Verified locally on Windows 11 x64 (
367cd009):cargo run --locked -p xtask -- policy(191 files ok) andcargo clippy --workspace --all-targets -- -D warnings(default and--all-features): clean.cargo test -p victory-hle --lib modules::xasync: 14 passed, 0 failed.cargo test -p victory-hle --all-targets: 153 lib + 2 integration tests passed, 0 failed.Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T10:37:35Z.
Thanks @fuzeofficlal — addressed both startup races and the test synchronization:
register_callreturning the newly registeredArc<Call>.pending_with(viapending_with_handle), clonedworker_state = Arc::clone(&state)before publishing the call intoCALLSand bound the spawned worker directly to the returnedArc<Call>, eliminating both the startupOP_CLEANUPUAF window and thecall(data.block)re-lookup identity race.sleep(50ms)incanceled_pending_with_keeps_state_alive_and_leaves_reused_block_alonewithfirst_worker.unwrap().join().unwrap()to deterministically synchronize after the old worker's full completion path.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.