gdk: stop serialized workers after the last port user #28

Closed
github-bot wants to merge 1 commit from gh-pr/28/head into gh-pr/28/base
Owner

@⁠zerkend on GitHub · 2026-11-21 18:07 UTC · original
zerkend:codex/xasync-worker-cleanup → main · +89 −1 · 1 files · 63 commits · closed without merging

Library / area: compat-common / XTaskQueue

A serialized port worker waited forever after its final queue user released the port. It kept both the thread and an Arc alive even with an empty queue and the port marked terminated.

Exit when the queue is empty and its user count reaches zero. Reset serial_started while holding the queue lock so a completion marker queued later can restart the worker. Termination while another user still owns the port keeps the worker available for its completion marker.

Four tests cover final release, shared ownership, restarting for a late completion marker, and cancellation/marker ordering during a running callback.

Source of behaviour: the existing queue user-count and termination-marker contracts; Microsoft's MIT-licensed TaskQueue reference also tears down port execution resources: https://github.com/microsoft/libHttpClient/blob/main/Source/Task/TaskQueue.cpp . No reference code was copied.

Validation (Windows, Rust 1.100):

  • New regression tests against the original worker: 0/4 pass; with the fix: 4/4 pass.
  • cargo test --locked -p compat-common --lib: 36 passed.
  • cargo test --locked -p compat-common --test gdk_rt --test gdk_rt_terminate: 2 passed.
  • git diff --check passes.

Build prerequisite: validation temporarily used only the public-checkout build guards from PR #12 at 03ab331 (compat-common/build.rs and src/online/mod.rs). Those changes are not included here. Unmodified main cannot compile compat-common because backend_data is absent.

Exports changed: none. No game/console files or binaries included.

Additional Windows smoke check on PR #12 plus this fix and #26: built xhost and all eight default runtime DLLs; xhost --load-only loaded the exact staged DLLs successfully (8 pass, 0 fail, 0 skip). No game was run.

**@⁠zerkend** on GitHub · 2026-11-21 18:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/28) `zerkend:codex/xasync-worker-cleanup` → `main` · +89 −1 · 1 files · 63 commits · closed without merging **Library / area:** compat-common / XTaskQueue A serialized port worker waited forever after its final queue user released the port. It kept both the thread and an Arc<Port> alive even with an empty queue and the port marked terminated. Exit when the queue is empty and its user count reaches zero. Reset `serial_started` while holding the queue lock so a completion marker queued later can restart the worker. Termination while another user still owns the port keeps the worker available for its completion marker. Four tests cover final release, shared ownership, restarting for a late completion marker, and cancellation/marker ordering during a running callback. **Source of behaviour:** the existing queue user-count and termination-marker contracts; Microsoft's MIT-licensed TaskQueue reference also tears down port execution resources: https://github.com/microsoft/libHttpClient/blob/main/Source/Task/TaskQueue.cpp . No reference code was copied. **Validation** (Windows, Rust 1.100): - New regression tests against the original worker: 0/4 pass; with the fix: 4/4 pass. - `cargo test --locked -p compat-common --lib`: 36 passed. - `cargo test --locked -p compat-common --test gdk_rt --test gdk_rt_terminate`: 2 passed. - `git diff --check` passes. **Build prerequisite:** validation temporarily used only the public-checkout build guards from PR #12 at 03ab331 (`compat-common/build.rs` and `src/online/mod.rs`). Those changes are not included here. Unmodified main cannot compile compat-common because backend_data is absent. **Exports changed:** none. No game/console files or binaries included. Additional Windows smoke check on PR #12 plus this fix and #26: built xhost and all eight default runtime DLLs; xhost --load-only loaded the exact staged DLLs successfully (8 pass, 0 fail, 0 skip). No game was run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:44 +00:00
github-bot closed this pull request 2026-11-26 06:07:44 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 21:44 UTC · original

Overlap note: #48 (mine) rewrites the queue part of gdk/rt.rs to match libHttpClient's TaskQueue. Serialized ports there use the system thread pool with the reference single-drainer counter, so no per-port worker thread exists, and the leak this PR fixes disappears with it. #48 also runs 55 scenarios against both the emulator and the real PC xgameruntime.dll. If #48 is not taken, this PR is the minimal fix for the same leak. I can port your 4 regression scenarios into #48's suite so they keep running either way.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:44 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/28#issuecomment-7069689070) Overlap note: #48 (mine) rewrites the queue part of `gdk/rt.rs` to match libHttpClient's TaskQueue. Serialized ports there use the system thread pool with the reference single-drainer counter, so no per-port worker thread exists, and the leak this PR fixes disappears with it. #48 also runs 55 scenarios against both the emulator and the real PC xgameruntime.dll. If #48 is not taken, this PR is the minimal fix for the same leak. I can port your 4 regression scenarios into #48's suite so they keep running either way.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:13 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). Superseded: ensure_serial already resets and exits when the last user leaves. The tests are also carried in #48.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/28#issuecomment-7079652668) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Superseded: ensure_serial already resets and exits when the last user leaves. The tests are also carried in #48.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.