xtaskqueue: preserve other work on shared ports #403

Closed
lordon1a wants to merge 1 commit from upstream-pr/403 into main
lordon1a commented 2026-11-24 02:57:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T02:57:25Z.


AI-assisted.

Problem

Composite XTaskQueue instances created via XTaskQueueCreateComposite share underlying Port objects, but XTaskQueueTerminate drained all pending tasks from every port on the terminating queue — canceling callbacks queued by other live queues sharing the same port. In addition, a delayed callback already accepted before termination could still be pushed onto a shared port after terminated was set.

Fix

  • Tag queued PendingTask entries with the owning queue's Arc<AtomicBool> cancellation flag.
  • In Port::submit, check owner.load(Ordering::Acquire) under the port lock and immediately run late deliveries as canceled instead of enqueueing them.
  • In XTaskQueueTerminate, retain tasks owned by other queues on shared ports and cancel only tasks belonging to the terminating queue.
  • Add unit test modules::xasync::tests::terminating_one_queue_keeps_other_work_on_the_shared_port.

Verification

  • cargo xtask policy: 151 files ok
  • cargo test -p victory-hle xasync: 6 passed; 0 failed
  • cargo clippy -p victory-hle --all-targets: 0 warnings in xasync.rs
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573589846 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/403). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T02:57:25Z. --- AI-assisted. ### Problem Composite `XTaskQueue` instances created via `XTaskQueueCreateComposite` share underlying `Port` objects, but `XTaskQueueTerminate` drained *all* pending tasks from every port on the terminating queue — canceling callbacks queued by other live queues sharing the same port. In addition, a delayed callback already accepted before termination could still be pushed onto a shared port after `terminated` was set. ### Fix - Tag queued `PendingTask` entries with the owning queue's `Arc<AtomicBool>` cancellation flag. - In `Port::submit`, check `owner.load(Ordering::Acquire)` under the port lock and immediately run late deliveries as canceled instead of enqueueing them. - In `XTaskQueueTerminate`, retain tasks owned by other queues on shared ports and cancel only tasks belonging to the terminating queue. - Add unit test `modules::xasync::tests::terminating_one_queue_keeps_other_work_on_the_shared_port`. ### Verification - `cargo xtask policy`: `151 files ok` - `cargo test -p victory-hle xasync`: `6 passed; 0 failed` - `cargo clippy -p victory-hle --all-targets`: 0 warnings in `xasync.rs`
copilot-pull-request-reviewer[bot commented 2026-11-24 06:52:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T02:57:36Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6033001414 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/403#pullrequestreview-6033001414). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-24T02:57:36Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
mercuryVM commented 2026-11-24 06:52:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:28:13Z.

Review: APPROVED


Tested 4ee6efa on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed), including terminating_one_queue_keeps_other_work_on_the_shared_port.

  • Each queued task now records its queue's terminated flag. XTaskQueueTerminate cancels only the entries whose flag is its own (Arc::ptr_eq), so a composite queue's work on a shared port survives another queue's termination.
  • submit checks the flag under the port lock, so a delivery that races with terminate is either queued before the drain or run as canceled. It can't land on the port afterwards.
  • Returning false there also keeps monitors from being told about a task that was never queued.
  • Immediate and ThreadPool ports ignore the flag, as before. Those never held queued tasks to cancel.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034666802 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/403#pullrequestreview-6034666802). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T06:28:13Z. **Review:** APPROVED --- Tested 4ee6efa on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed), including `terminating_one_queue_keeps_other_work_on_the_shared_port`. - Each queued task now records its queue's `terminated` flag. `XTaskQueueTerminate` cancels only the entries whose flag is its own (`Arc::ptr_eq`), so a composite queue's work on a shared port survives another queue's termination. - `submit` checks the flag under the port lock, so a delivery that races with terminate is either queued before the drain or run as canceled. It can't land on the port afterwards. - Returning `false` there also keeps monitors from being told about a task that was never queued. - `Immediate` and `ThreadPool` ports ignore the flag, as before. Those never held queued tasks to cancel. No issues found. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-24 06:55:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:31:59Z.


Thanks @lordon1a for keeping shared-port work independent across queue termination. I tested head 4ee6efa4a0c686d1def48c4bfebd45caa0aa9d75 with:

cargo test --locked -p victory-hle --lib terminating_one_queue_keeps_other_work_on_the_shared_port -- --test-threads=1

Result: 1 passed, 0 failed (86 filtered out). The test terminates one async queue while another queue has work on the shared port and verifies the other work still completes. This is a synthetic XAsync test, not a title workflow.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122105307 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/403#issuecomment-7122105307). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:31:59Z. --- Thanks @lordon1a for keeping shared-port work independent across queue termination. I tested head `4ee6efa4a0c686d1def48c4bfebd45caa0aa9d75` with: ``` cargo test --locked -p victory-hle --lib terminating_one_queue_keeps_other_work_on_the_shared_port -- --test-threads=1 ``` Result: 1 passed, 0 failed (86 filtered out). The test terminates one async queue while another queue has work on the shared port and verifies the other work still completes. This is a synthetic XAsync test, not a title workflow.
upstream-sync closed this pull request 2026-11-24 19:02:05 +00:00

Pull request closed

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
Marvisak/VIctory!403
No description provided.