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

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

@⁠Caasares on GitHub · 2026-11-24 23:21 UTC · original
Caasares:fix/xtaskqueue-composite-terminate → main · +264 −3 · 1 files · 1 commits · open

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.

**@⁠Caasares** on GitHub · 2026-11-24 23:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/296) `Caasares:fix/xtaskqueue-composite-terminate` → `main` · +264 −3 · 1 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:40:11 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/296/head:github-bot/gh-296'
git switch 'github-bot/gh-296'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-296'
git switch 'github-bot/gh-296'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-296'
git switch 'github-bot/gh-296'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-296'
git switch 'main'
git merge --squash 'github-bot/gh-296'
git switch 'main'
git merge --ff-only 'github-bot/gh-296'
git switch 'main'
git merge 'github-bot/gh-296'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.