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

Merged
gefydev merged 1 commit from upstream-pr/54 into main 2026-11-23 09:44:41 +00:00
gefydev commented 2026-11-22 22:46:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gefydev on 2026-11-22T22:46:32Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6548808605 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/54). Originally posted by [gefydev](https://github.com/gefydev) on 2026-11-22T22:46:32Z. --- `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.
upstream-sync closed this pull request 2026-11-24 06:56:56 +00:00
ivall commented 2026-11-24 07:00:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T09:45:13Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7097052255 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/54#issuecomment-7097052255). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T09:45:13Z. --- 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!
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
xcl-dev/xcl!53
No description provided.