Task queues: terminating cancels delayed callbacks before the termination callback #54

Manually merged
github merged 1 commit from gh-pr/54/head into gh-pr/54/base 2026-11-26 04:06:49 +00:00
Owner

@⁠gefydev on GitHub · 2026-11-22 22:46 UTC · original
gefydev:taskqueue-terminate-delayed → main · +35 −0 · 1 files · 1 commits · merged 2026-11-23 09:44 UTC

XTaskQueueTerminate (taskqueue.rs) cancels the callbacks queued on the queue's ports, but not delayed callbacks (XTaskQueueSubmitDelayedCallback, also used by XAsyncSchedule with a delay) that are still waiting in the timer heap. Those only count in inflight once they are due. So the wait in Terminate doesn't hold the termination callback for them: it runs first, and the delayed callback runs later, canceled, up to its full delay after the queue was terminated. A title often frees in the termination callback what it passed as those callbacks' context.

libHttpClient moves a terminating port's pending delayed entries to its active list (CancelPendingEntries(cxt, true) in TaskQueuePortImpl::Terminate), so they are invoked canceled before termination completes. Terminate now takes the queue's entries out of the timer heap and invokes them canceled before the termination callback, the same way it already handles the port items. Delayed callbacks of other queues stay in the heap.

Validation

  • New test terminate_cancels_delayed_callbacks_before_its_own_callback: a 60 s delayed callback, then Terminate(wait = true) with a termination callback. On main only ["terminated"] is recorded; with the change it is ["delayed, canceled", "terminated"].
  • cargo test -p xcl --lib: 340 passed, 0 failed, on Windows GNU under Wine.
**@⁠gefydev** on GitHub · 2026-11-22 22:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/54) `gefydev:taskqueue-terminate-delayed` → `main` · +35 −0 · 1 files · 1 commits · merged 2026-11-23 09:44 UTC `XTaskQueueTerminate` (`taskqueue.rs`) cancels the callbacks queued on the queue's ports, but not delayed callbacks (`XTaskQueueSubmitDelayedCallback`, also used by `XAsyncSchedule` with a delay) that are still waiting in the timer heap. Those only count in `inflight` once they are due. So the wait in `Terminate` doesn't hold the termination callback for them: it runs first, and the delayed callback runs later, canceled, up to its full delay after the queue was terminated. A title often frees in the termination callback what it passed as those callbacks' context. libHttpClient moves a terminating port's pending delayed entries to its active list (`CancelPendingEntries(cxt, true)` in `TaskQueuePortImpl::Terminate`), so they are invoked canceled before termination completes. `Terminate` now takes the queue's entries out of the timer heap and invokes them canceled before the termination callback, the same way it already handles the port items. Delayed callbacks of other queues stay in the heap. ## Validation - New test `terminate_cancels_delayed_callbacks_before_its_own_callback`: a 60 s delayed callback, then `Terminate(wait = true)` with a termination callback. On `main` only `["terminated"]` is recorded; with the change it is `["delayed, canceled", "terminated"]`. - `cargo test -p xcl --lib`: 340 passed, 0 failed, on Windows GNU under Wine.
XTaskQueueTerminate canceled the callbacks queued on the queue's ports,
but not delayed ones still waiting in the timer heap. Those count as in
flight only once due, so the termination callback ran first and the
delayed callback ran (canceled) up to its delay later – when a title may
already have freed what it passes as the callback's context.

They are now taken out of the timer heap and invoked canceled before the
termination callback, as libHttpClient's CancelPendingEntries does when a
port terminates.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:06:46 +00:00
github manually merged commit 6a270f5362 into gh-pr/54/base 2026-11-26 04:06:49 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 09:45 UTC · original

Merged (2e000cb). The module comment of taskqueue.rs now describes termination as it is after this and #57 (e38cb65).

Tested on Windows 11 (RX 9070): cargo test --workspace green (lib 351, e2e), and a 45 s Unicorn Overlord run on the release build (VFS hooks active, ~60 fps, clean exit). Thanks!

**@⁠ivall** on GitHub · 2026-11-23 09:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/54#issuecomment-7097052255) Merged (2e000cb). The module comment of `taskqueue.rs` now describes termination as it is after this and #57 (e38cb65). Tested on Windows 11 (RX 9070): `cargo test --workspace` green (lib 351, e2e), and a 45 s Unicorn Overlord run on the release build (VFS hooks active, ~60 fps, clean exit). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.