Skip to content

HLE: XTaskQueueTerminate cancels only its own tasks on shared ports - #1673

Open
Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/hle-xtaskqueue-shared-ports-1637
Open

Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/hle-xtaskqueue-shared-ports-1637

Conversation

@Calvix2k

Copy link
Copy Markdown
Contributor

Fixes #1637.

Ports the verified fix from @AndyLatimer's fork (commit 47e61a2 by Manuel Pérez), applied unchanged onto ffe310e; the commit keeps its original author.

Summary

XTaskQueueTerminate drained every port unconditionally, so terminating one queue cancelled the queued callbacks and pending XAsync work of every other queue sharing that port (manual, serialized, or composite queues mapping both ports to one shared port).

  • Each Queue gets a monotonic id, shared across XTaskQueueDuplicateHandle and distinct for composite queues.
  • Queued entries carry their owner id; Port::take_owned removes only the terminating queue's tasks, keeping other queues' order.
  • Port::submit re-checks queue.terminated under the port lock, so a task racing with termination is cancelled instead of enqueued after the drain.

Tests

Three new synthetic tests (also in the commit): shared manual port with duplicate handles and a composite queue on one port, shared serialized port, and pending XAsyncRun calls across composite queues. All pass with the fix and fail before it.

Validation

  • cargo test -p victory-hle --locked -- --test-threads=1 — passed (97 unit tests and 1 integration test).
  • cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings — passed.
  • cargo xtask policy — passed (154 files).
  • rustfmt --edition 2024 --check on the file reports only pre-existing hunks in untouched code.

@BaggyALPHA BaggyALPHA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three new shared-port tests passed independently on Windows. A synthetic reentrant-dispatch test found one remaining cancellation case. Two manual queues share their ports. Queue B has a work callback and a completion callback pending, and queue A has a completion callback pending. While B is terminating, its canceled work callback dispatches the shared completion port through A. B's completion then receives canceled=false, and A's completion correctly receives canceled=false.

The termination flag is already set on B when this happens. Port::take drops the submitting queue identity, and XTaskQueueDispatch always supplies false. The dispatcher needs to read the submitting queue's cancellation state when it invokes the callback, including on the serialized worker path. Microsoft's libHttpClient reference implementation does this in DrainOneItem using the entry's port context. Keeping shared cancellation state with the queued entry would let dispatch distinguish the two callbacks.

AI-assisted (Codex). Tested with synthetic callbacks.

Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 24, 2026

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: Windows-only code (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff.

XTaskQueueTerminate now cancels only the terminating queue's own tasks on shared ports: submit() takes an owner id + terminated flag, take_owned() collects only that owner's tasks, and two tests cover manual and serialized shared ports (record/hold extern callbacks log cancellation). Previously terminating one queue could cancel another queue's tasks on the same port — a real correctness fix for shared-port titles.

@avt0m4t48

Copy link
Copy Markdown

I independently tested exact head dda166c8 with a source-built public queue API fixture. It preserves sibling FIFO and reproduces the reviewed manual reentrant case. A separate serialized-worker control also runs the terminating owner's already queued completion with canceled=false where the owner state expects true.

A follow-up that carries the submitting queue's cancellation state into both dispatch paths passed all 13 isolated Linux tests, including the three API cases, which also passed 25 repeats. The exact PR plus follow-up passed Windows-target checks for victory-hle and victory-gpu tests with blake3/pure. Windows runtime was outside these checks. Tested follow-up with API fixtures

AI-assisted using Codex.

@Calvix2k
Calvix2k force-pushed the codex/hle-xtaskqueue-shared-ports-1637 branch from dda166c to 0ef707e Compare November 25, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HLE: XTaskQueueTerminate cancels other queues' queued tasks on shared ports (fix on a fork)

5 participants