hle(xasync): cancel only owning queue callbacks on XTaskQueueTerminate #296

Open
Caasares wants to merge 1 commit from upstream-pr/296 into main
Caasares commented 2026-11-24 23:21:15 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Caasares on 2026-11-24T23:21:15Z.


Fixes #243

Root Cause

XTaskQueueTerminate previously drained every pending Task from each Port referenced by the terminating Queue (lock(&port.tasks).drain(..)). Because composite queues (XTaskQueueCreateComposite) share Arc<Port> instances with their underlying queues (such as a manual base queue), terminating a composite queue canceled pending callbacks submitted through other queues sharing those ports.

Fix

  • Assigned each Queue a monotonic u64 identifier (NEXT_QUEUE_ID) and stored the submitting queue_id on each Task in Queue::submit (crates/victory-hle/src/modules/xasync.rs).
  • Updated XTaskQueueTerminate to retain callbacks belonging to other queues in FIFO order (tasks.retain(...)), draining only tasks where task.queue_id == queue.id across both WORK and COMPLETION ports.
  • Dropped the port.tasks mutex guard before calling port.ready.notify_all() and invoking canceled callbacks (canceled = true), preventing deadlocks if a cancellation callback re-enters queue APIs.
  • Added regression unit tests in crates/victory-hle/src/modules/xasync.rs:
    • terminating_composite_queue_preserves_base_queue_callbacks: reproduces #243 across WORK and COMPLETION ports with a manual base queue and a composite queue.
    • terminating_composite_queue_preserves_fifo_and_unlocks_before_canceling: verifies FIFO preservation across interleaved submissions and re-entrant XTaskQueueSubmitDelayedCallback calls from inside a cancellation callback.

Verification

All commands run inside wt-vf-243:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
  • cargo test --workspace --locked: passed (498 passed; 0 failed; 7 ignored across workspace; victory-hle unit tests 97 passed; 0 failed, xtask asset-policy 4 passed; 0 failed)
  • cargo fmt --all -- --check: failed only on pre-existing formatting differences in untouched files across the repository; newly added code in crates/victory-hle/src/modules/xasync.rs was checked with rustfmt --edition 2024 --check.

Note: AI-assisted fix; contains no game files, code, or assets.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593416129 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/296). Originally posted by [Caasares](https://github.com/Caasares) on 2026-11-24T23:21:15Z. --- Fixes #243 ## Root Cause `XTaskQueueTerminate` previously drained every pending `Task` from each `Port` referenced by the terminating `Queue` (`lock(&port.tasks).drain(..)`). Because composite queues (`XTaskQueueCreateComposite`) share `Arc<Port>` instances with their underlying queues (such as a manual base queue), terminating a composite queue canceled pending callbacks submitted through other queues sharing those ports. ## Fix - Assigned each `Queue` a monotonic `u64` identifier (`NEXT_QUEUE_ID`) and stored the submitting `queue_id` on each `Task` in `Queue::submit` (`crates/victory-hle/src/modules/xasync.rs`). - Updated `XTaskQueueTerminate` to retain callbacks belonging to other queues in FIFO order (`tasks.retain(...)`), draining only tasks where `task.queue_id == queue.id` across both `WORK` and `COMPLETION` ports. - Dropped the `port.tasks` mutex guard before calling `port.ready.notify_all()` and invoking canceled callbacks (`canceled = true`), preventing deadlocks if a cancellation callback re-enters queue APIs. - Added regression unit tests in `crates/victory-hle/src/modules/xasync.rs`: - `terminating_composite_queue_preserves_base_queue_callbacks`: reproduces #243 across `WORK` and `COMPLETION` ports with a manual base queue and a composite queue. - `terminating_composite_queue_preserves_fifo_and_unlocks_before_canceling`: verifies FIFO preservation across interleaved submissions and re-entrant `XTaskQueueSubmitDelayedCallback` calls from inside a cancellation callback. ## Verification All commands run inside `wt-vf-243`: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `cargo test --workspace --locked`: passed (`498 passed; 0 failed; 7 ignored` across workspace; `victory-hle` unit tests `97 passed; 0 failed`, `xtask` asset-policy `4 passed; 0 failed`) - `cargo fmt --all -- --check`: failed only on pre-existing formatting differences in untouched files across the repository; newly added code in `crates/victory-hle/src/modules/xasync.rs` was checked with `rustfmt --edition 2024 --check`. Note: AI-assisted fix; contains no game files, code, or assets.
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/296:upstream-pr/296'
git switch 'upstream-pr/296'

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/296'
git switch 'upstream-pr/296'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/296'
git switch 'upstream-pr/296'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/296'
git switch 'main'
git merge --squash 'upstream-pr/296'
git switch 'main'
git merge --ff-only 'upstream-pr/296'
git switch 'main'
git merge 'upstream-pr/296'
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
fxceless/victory-fork!296
No description provided.