Release PIX transport resources when an XBTP accept finishes #234

Closed
github-bot wants to merge 2 commits from gh-pr/234/head into gh-pr/234/base
Owner

@⁠bambermf on GitHub · 2026-11-23 06:24 UTC · original
bambermf:fix/pixrt-listener-cleanup → main · +46 −12 · 2 files · 2 commits · closed without merging

Library / area — Shared PIX runtime in pixrt and pixrt10, device-engine XBTP transport.

Exports changed — None.

Source of the behaviour — Static inspection of a local 19041 console pixrt10.dll with headless IDA. The listen/accept routine at RVA 0x29820 calls cleanup on failure. The cleanup at 0x29b84 releases the listener reference and handles any accepted connection. The destructor at 0x29760 balances the system reference and disposes of the cancellation event. The runtime measurements below exercise the emulator with its in-process XBTP implementation.

What was wrong

Cancelling a pending accept cleared the published PIX link, but service 0x1080 still had one listener reference. Neither that listener nor the cancellation event was closed. The session-setup fallback after a successful accept also retained the listener, the system reference and the numeric value of the closed connection handle.

The change

Release each acquired listener reference when accept finishes. Close the listener on its last reference, balance system initialization on all exits after acquisition, and clear the published link and dispose of its event under the link lock. Clear the accepted handle when closing the unsupported tool session. Session dispatch remains unfinished.

Measurements and tests

Pending accept cancelled through its event Upstream With this change
PIX listener references after the link disappears 1 0
In-process endpoint gone, then a fresh listen on the same port succeeds Test stopped at the reference assertion Passed

The release suites for both PIX crates passed all 38 tests with local build 19041 DLL fixtures available for the export-table comparisons. This includes cancellation and reopening service 0x1080. Missing listener handles now produce a diagnostic and return from cleanup. No live PIX tool session or gameplay test was performed.

**@⁠bambermf** on GitHub · 2026-11-23 06:24 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/234) `bambermf:fix/pixrt-listener-cleanup` → `main` · +46 −12 · 2 files · 2 commits · closed without merging **Library / area** — Shared PIX runtime in `pixrt` and `pixrt10`, device-engine XBTP transport. **Exports changed** — None. **Source of the behaviour** — Static inspection of a local 19041 console `pixrt10.dll` with headless IDA. The listen/accept routine at RVA `0x29820` calls cleanup on failure. The cleanup at `0x29b84` releases the listener reference and handles any accepted connection. The destructor at `0x29760` balances the system reference and disposes of the cancellation event. The runtime measurements below exercise the emulator with its in-process XBTP implementation. ### What was wrong Cancelling a pending accept cleared the published PIX link, but service `0x1080` still had one listener reference. Neither that listener nor the cancellation event was closed. The session-setup fallback after a successful accept also retained the listener, the system reference and the numeric value of the closed connection handle. ### The change Release each acquired listener reference when accept finishes. Close the listener on its last reference, balance system initialization on all exits after acquisition, and clear the published link and dispose of its event under the link lock. Clear the accepted handle when closing the unsupported tool session. Session dispatch remains unfinished. ### Measurements and tests | Pending accept cancelled through its event | Upstream | With this change | |---|---|---| | PIX listener references after the link disappears | 1 | 0 | | In-process endpoint gone, then a fresh listen on the same port succeeds | Test stopped at the reference assertion | Passed | The release suites for both PIX crates passed all 38 tests with local build 19041 DLL fixtures available for the export-table comparisons. This includes cancellation and reopening service `0x1080`. Missing listener handles now produce a diagnostic and return from cleanup. No live PIX tool session or gameplay test was performed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:15:04 +00:00
github-bot closed this pull request 2026-11-26 06:15:04 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 06:33 UTC · original

Thanks, releasing the listener, the system reference and the cancel event on every path is the right fix, and the reopen check on 0x1080 in the test is a good way to prove it.

One change before it can be applied: release_listener uses .expect("acquired PIX listener"). A panic inside a compat DLL takes the whole title down, which compat crates must never do. Please replace it with a logged early return, for example a record(...) line saying the listener was not found and then returning. After that, it goes into the next build (r32h), with the pixrt tests passing.

**@⁠omonkeyz** on GitHub · 2026-11-23 06:33 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/234#issuecomment-7093441749) Thanks, releasing the listener, the system reference and the cancel event on every path is the right fix, and the reopen check on 0x1080 in the test is a good way to prove it. One change before it can be applied: `release_listener` uses `.expect("acquired PIX listener")`. A panic inside a compat DLL takes the whole title down, which compat crates must never do. Please replace it with a logged early return, for example a `record(...)` line saying the listener was not found and then returning. After that, it goes into the next build (r32h), with the pixrt tests passing.
Author
Owner

@⁠bambermf on GitHub · 2026-11-23 06:50 UTC · original

Fixed in 384b3c6. If cleanup can’t find the PIX listener, it now logs a diagnostic and returns without panicking. All 38 release tests across pixrt and pixrt10 passed, including the test that cancels the listener and reopens service 0x1080. Thanks for catching this.

**@⁠bambermf** on GitHub · 2026-11-23 06:50 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/234#issuecomment-7093721247) Fixed in 384b3c6. If cleanup can’t find the PIX listener, it now logs a diagnostic and returns without panicking. All 38 release tests across `pixrt` and `pixrt10` passed, including the test that cancels the listener and reopens service `0x1080`. Thanks for catching this.
Author
Owner

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

Included in #250, which is being applied; this will be closed when that ships.

**@⁠omonkeyz** on GitHub · 2026-11-23 13:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/234#issuecomment-7102657024) Included in #250, which is being applied; this will be closed when that ships.
Author
Owner

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

Applied on main in 8b16440 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/234#issuecomment-7163370728) Applied on main in 8b16440 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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