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

Closed
zerkend wants to merge 0 commits from upstream-pr/28 into main
zerkend commented 2026-11-21 18:07:02 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by zerkend on 2026-11-21T18:07:02Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6532530316 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/28). Originally posted by [zerkend](https://github.com/zerkend) on 2026-11-21T18:07:02Z. --- **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.
QuentinDanblon commented 2026-11-21 21:44:41 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T21:44:41Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7069689070 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/28#issuecomment-7069689070). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T21:44:41Z. --- 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.
omonkeyz commented 2026-11-22 13:13:13 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:13:13Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079652668 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/28#issuecomment-7079652668). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:13:13Z. --- 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

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
omonkeyz/xbox-emulator!28
No description provided.