XGameRuntime: XNetworking change registrations fire the initial callback #1227

Open
emirduran707 wants to merge 1 commit from upstream-pr/1237 into main
emirduran707 commented 2026-11-24 13:34:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T13:34:06Z.


XNetworkingRegisterConnectivityHintChanged and XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged handed out a token and never called the callback. Microsoft's documentation says both send a first callback when they register: the connectivity one "registers a "connectivity hint changed" notification and sends an initial notification callback", and the port one "always fires an initial notification callback". The network-initialization guidance builds on that: a title registers and then waits for the callback to report networkInitialized. Under XCL such a title waited forever, or treated the network as not up.

Both now write the token, then queue one callback on the queue's completion port through xasync::submit_callback, as notify_association does for user-association changes. The connectivity callback carries the current hint from XNetworkingGetConnectivityHint, and the port callback carries DEFAULT_UDP_PORT. A null callback is E_INVALIDARG, as for XUserRegisterForDeviceAssociationChanged. If the queue refuses the callback, its record is freed and a warning is logged.

What is in it

  • crates/xcl/src/hle/xgameruntime/networking.rs: the first callbacks; test register_fires_an_initial_callback. It uses an immediate queue and checks that each callback runs once, with network_initialized true and port 3074, and that a null callback is refused.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on e2a4b1d: 742 passed, 0 failed, 41 ignored; no SKIPPED GPU tests
  • the new test without the change in the two register functions: callback count left: 0, right: 1; with it it passes

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19650 MB

this PR:

xcl-smoke v1
commit: e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1481 (PresentX 1481)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19710 MB

Not tested

  • A title that waits for the first connectivity callback; the smoke title's run is a regression check only.
  • With #494 merged, the first callback carries its XCL_NETWORK=0 level (it comes from XNetworkingGetConnectivityHint); not run together.
  • NVIDIA and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5473150919 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T13:34:06Z. --- `XNetworkingRegisterConnectivityHintChanged` and `XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged` handed out a token and never called the callback. Microsoft's documentation says both send a first callback when they register: the connectivity one "registers a "connectivity hint changed" notification and sends an initial notification callback", and the port one "always fires an initial notification callback". The network-initialization guidance builds on that: a title registers and then waits for the callback to report `networkInitialized`. Under XCL such a title waited forever, or treated the network as not up. Both now write the token, then queue one callback on the queue's completion port through `xasync::submit_callback`, as `notify_association` does for user-association changes. The connectivity callback carries the current hint from `XNetworkingGetConnectivityHint`, and the port callback carries `DEFAULT_UDP_PORT`. A null callback is `E_INVALIDARG`, as for `XUserRegisterForDeviceAssociationChanged`. If the queue refuses the callback, its record is freed and a warning is logged. **What is in it** - `crates/xcl/src/hle/xgameruntime/networking.rs`: the first callbacks; test `register_fires_an_initial_callback`. It uses an immediate queue and checks that each callback runs once, with `network_initialized` true and port 3074, and that a null callback is refused. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace -- --test-threads=4` on e2a4b1d: 742 passed, 0 failed, 41 ignored; no SKIPPED GPU tests - the new test without the change in the two register functions: callback count `left: 0`, `right: 1`; with it it passes **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1541 (PresentX 1541) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19650 MB ``` this PR: ``` xcl-smoke v1 commit: e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1481 (PresentX 1481) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19710 MB ``` **Not tested** - A title that waits for the first connectivity callback; the smoke title's run is a regression check only. - With #494 merged, the first callback carries its `XCL_NETWORK=0` level (it comes from `XNetworkingGetConnectivityHint`); not run together. - NVIDIA and Intel GPUs. **AI use** - Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DavidM1911 commented 2026-11-24 14:06:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:02:21Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib lib xgameruntime: 74 passed, 0 failed.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7133736920 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1237#issuecomment-7133736920). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T14:02:21Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl --lib lib xgameruntime: 74 passed, 0 failed. Thanks!
DavidM1911 commented 2026-11-26 05:05:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:17:25Z.


Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7182464019 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7182464019). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T04:17:25Z. --- Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
github-actions[bot] commented 2026-11-30 08:42:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:42:51Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273250761 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7273250761). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:42:51Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Grimkaaah commented 2026-11-30 12:05:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-30T12:05:24Z.


I compared this with the same registrations in my project. I checked it against the public XNetworking.h and the learn.microsoft.com pages for XNetworkingRegisterConnectivityHintChanged and XNetworkingUnregisterConnectivityHintChanged.

What I checked, all fine:

  • The token is written before the submit. An immediate completion port runs the callback inside the submit, so that order matters.
  • A null callback gives E_INVALIDARG; the header marks it _In_.
  • The record is freed when canceled is set.
  • Both callback signatures match the header's typedefs.
  • The hint pointer stays valid for the whole call.

Findings:

  1. Unregistering can't stop the initial callback. Both unregister functions still do nothing and return true (networking.rs:132 and :674). The initial callback now waits on the title's queue (a null queue means the process queue, a thread pool) until it is dispatched.

    • The Unregister page says that blocking on unregistration ensures "your callbacks are never invoked after an unregister call". It also says that with wait false, it returns false while a callback is running.
    • What breaks: a title registers on a manual queue, or during a busy frame. It then unregisters, for example at teardown, and frees context. The queued callback runs later with the freed context.

    Fix: keep a small table, token -> Arc<{alive, threads running the callback, Condvar}>, and put the Arc in InitialNotification.

    • The queued call checks alive before calling the title.
    • Unregister removes the entry and clears alive.
    • With wait, it waits for a call that is running on another thread, but not for one on its own thread. The page says unregistering with wait from inside the callback deadlocks.
    • Without wait, it returns false while a call is running.

    This is how we do it.

  2. A refused submit is ignored. notify_initial (networking.rs:73-80) only logs it, and the register functions still return S_OK with a token. This happens with a null queue after XTaskQueueSetCurrentProcessTaskQueue(nullptr), because queue_from returns None (E_INVALIDARG), and with a terminated queue (E_ABORT). The title then waits for a callback that never comes, which is the hang this PR fixes, with no error to show for it. Suggest returning the submit's HRESULT from the register function and not keeping the token. The docs don't say what the real runtime returns here; this is the choice we made.

Not checked: we haven't built or run this PR. We didn't test a title that waits for the callback, and didn't check how it behaves together with #494.

AI use: Claude Code (Claude Opus 5.5) reviewed this by comparing it with the same mechanism in my project, Victory Grimkaaah.

<!-- greyfinch-sync:ivall/xcl:comment:7277929291 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7277929291). Originally posted by [Grimkaaah](https://github.com/Grimkaaah) on 2026-11-30T12:05:24Z. --- I compared this with the same registrations in my project. I checked it against the public XNetworking.h and the learn.microsoft.com pages for XNetworkingRegisterConnectivityHintChanged and XNetworkingUnregisterConnectivityHintChanged. What I checked, all fine: - The token is written before the submit. An immediate completion port runs the callback inside the submit, so that order matters. - A null callback gives E_INVALIDARG; the header marks it `_In_`. - The record is freed when `canceled` is set. - Both callback signatures match the header's typedefs. - The hint pointer stays valid for the whole call. Findings: 1. Unregistering can't stop the initial callback. Both unregister functions still do nothing and return true (networking.rs:132 and :674). The initial callback now waits on the title's queue (a null queue means the process queue, a thread pool) until it is dispatched. - The Unregister page says that blocking on unregistration ensures "your callbacks are never invoked after an unregister call". It also says that with `wait` false, it returns false while a callback is running. - What breaks: a title registers on a manual queue, or during a busy frame. It then unregisters, for example at teardown, and frees `context`. The queued callback runs later with the freed context. Fix: keep a small table, token -> `Arc<{alive, threads running the callback, Condvar}>`, and put the Arc in `InitialNotification`. - The queued call checks `alive` before calling the title. - Unregister removes the entry and clears `alive`. - With `wait`, it waits for a call that is running on another thread, but not for one on its own thread. The page says unregistering with `wait` from inside the callback deadlocks. - Without `wait`, it returns false while a call is running. This is how we do it. 2. A refused submit is ignored. `notify_initial` (networking.rs:73-80) only logs it, and the register functions still return S_OK with a token. This happens with a null queue after `XTaskQueueSetCurrentProcessTaskQueue(nullptr)`, because `queue_from` returns None (E_INVALIDARG), and with a terminated queue (E_ABORT). The title then waits for a callback that never comes, which is the hang this PR fixes, with no error to show for it. Suggest returning the submit's HRESULT from the register function and not keeping the token. The docs don't say what the real runtime returns here; this is the choice we made. Not checked: we haven't built or run this PR. We didn't test a title that waits for the callback, and didn't check how it behaves together with #494. AI use: Claude Code (Claude Opus 5.5) reviewed this by comparing it with the same mechanism in my project, Victory Grimkaaah.
BBareth commented 2026-11-30 23:29:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:29:27Z.


merge-check claim
head: e2a4b1d319

<!-- greyfinch-sync:ivall/xcl:comment:7295177615 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7295177615). Originally posted by [BBareth](https://github.com/BBareth) on 2026-11-30T23:29:27Z. --- merge-check claim head: e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1
BBareth commented 2026-11-30 23:38:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:38:04Z.


merge-check
base: d0832e614f
head: e2a4b1d319
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, run earlier today on the same commit: 2890 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The new test register_fires_an_initial_callback ran and passed.
review: no blocking finding; one file (+104/-9), every line read. The two register functions now queue one notification with the current value (UDP port 3074, the current connectivity hint) on the completion port of the queue they are given, write the token before queuing, and refuse a null callback with E_INVALIDARG; a record the queue does not take is freed and a warning is logged. Two things to know, neither blocking: (1) the queued notification is not tied to the token, so a title that unregisters (even with wait = true) before its queue has dispatched it still gets the callback afterwards; with an immediate queue, as in the test, it runs inside the register call and this cannot happen; (2) a null callback was accepted before and is refused now. Not tested here: a retail title that waits for these callbacks.
performance: none: one small allocation and one queued callback per registration.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

<!-- greyfinch-sync:ivall/xcl:comment:7295350708 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7295350708). Originally posted by [BBareth](https://github.com/BBareth) on 2026-11-30T23:38:04Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, run earlier today on the same commit: 2890 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The new test `register_fires_an_initial_callback` ran and passed. review: no blocking finding; one file (+104/-9), every line read. The two register functions now queue one notification with the current value (UDP port 3074, the current connectivity hint) on the completion port of the queue they are given, write the token before queuing, and refuse a null callback with `E_INVALIDARG`; a record the queue does not take is freed and a warning is logged. Two things to know, neither blocking: (1) the queued notification is not tied to the token, so a title that unregisters (even with wait = true) before its queue has dispatched it still gets the callback afterwards; with an immediate queue, as in the test, it runs inside the register call and this cannot happen; (2) a null callback was accepted before and is refused now. Not tested here: a retail title that waits for these callbacks. performance: none: one small allocation and one queued callback per registration. verdict: safe to merge hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Foniass commented 2026-12-01 05:12:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:12:11Z.


Triage (#1607) – head e2a4b1d

No open or merged PR makes the same change: main's XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged / XNetworkingRegisterConnectivityHintChanged still ignore the queue and callback.
Overlap to know about: #1828 (tests only) asserts that both register functions return S_OK with a null callback, while this PR returns E_INVALIDARG for cb == 0; whichever lands second has to reconcile that test.
The callback signatures in udp_port_changed_call / connectivity_hint_changed_call match the GDK ones, and the record is freed on both the run and the failed-submit paths.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301524463 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7301524463). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:12:11Z. --- **Triage (#1607)** – head e2a4b1d No open or merged PR makes the same change: main's `XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged` / `XNetworkingRegisterConnectivityHintChanged` still ignore the queue and callback. Overlap to know about: #1828 (tests only) asserts that both register functions return `S_OK` with a null callback, while this PR returns `E_INVALIDARG` for `cb == 0`; whichever lands second has to reconcile that test. The callback signatures in `udp_port_changed_call` / `connectivity_hint_changed_call` match the GDK ones, and the record is freed on both the run and the failed-submit paths. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
cj-tomlin commented 2026-12-02 17:24:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by cj-tomlin on 2026-12-02T17:24:34Z.


Test report, head e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1 merged onto main 5eaadb54c14e0fc29597b2a1689d7dbd83491303 (clean, merge fdb0e78e).

  • Hardware: NVIDIA GeForce RTX 3080 10 GB, driver 621.40, AMD Ryzen 7 7800X3D, Windows 11 build 26300, debug build.
  • cargo build --workspace: ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 2975 passed, 0 failed, 52 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll), the same 27 as plain main (2974 passed, 0 failed, 52 ignored) on this machine.
  • The new register_fires_an_initial_callback passes, and fails at its first call count (left 0, right 1) when I take the two notify_initial calls back out of the merged tree.

Diff read (+104/-9, xgameruntime/networking.rs), CPU only. Minor, not blocking: unregistering does not cancel an initial callback that is still queued, so on a non-immediate queue it can still run after XNetworkingUnregister…Changed.

Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.

<!-- greyfinch-sync:ivall/xcl:comment:7353274398 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7353274398). Originally posted by [cj-tomlin](https://github.com/cj-tomlin) on 2026-12-02T17:24:34Z. --- Test report, head `e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1` merged onto `main` `5eaadb54c14e0fc29597b2a1689d7dbd83491303` (clean, merge `fdb0e78e`). - Hardware: NVIDIA GeForce RTX 3080 10 GB, driver 621.40, AMD Ryzen 7 7800X3D, Windows 11 build 26300, debug build. - `cargo build --workspace`: ok. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2975 passed, 0 failed, 52 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll), the same 27 as plain `main` (2974 passed, 0 failed, 52 ignored) on this machine. - The new `register_fires_an_initial_callback` passes, and fails at its first call count (left 0, right 1) when I take the two `notify_initial` calls back out of the merged tree. Diff read (+104/-9, `xgameruntime/networking.rs`), CPU only. Minor, not blocking: unregistering does not cancel an initial callback that is still queued, so on a non-immediate queue it can still run after `XNetworkingUnregister…Changed`. Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.
grathepic commented 2026-12-02 22:33:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by grathepic on 2026-12-02T22:33:43Z.


merge-check
base: 078358a058
head: e2a4b1d319
merge: clean (git diff --check origin/main..HEAD clean)
build: cargo +1.98.1-x86_64-pc-windows-msvc build --offline --locked --workspace -> ok
tests: cargo +1.98.1-x86_64-pc-windows-msvc test --offline --locked --workspace --no-fail-fast -- --test-threads=4 (with XCL_DXC_DIR=C:\VulkanSDK\1.4.363.0\Bin, XCL_SAMPLE_* unset) -> 3007 passed, 0 failed, 52 ignored across 44 harnesses; SKIPPED: 27 notices (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps, 1 no dxil.dll, 1 cannot disable the driver cache (Windows Developer Mode required)); failing: none. New test hle::xgameruntime::networking::tests::register_fires_an_initial_callback ran and passed.
title run: none (no retail title run on this machine; note this PR changes runtime code outside tests and the earlier merge-check also lacks a title run: past the loading screen)
review: Full diff read (+104/-9, crates/xcl/src/hle/xgameruntime/networking.rs). Blocking findings: (1) Use-after-free hazard on unregistration: XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged (networking.rs:118-130) and XNetworkingRegisterConnectivityHintChanged (networking.rs:676-690) now queue asynchronous InitialNotification<T> callbacks holding a raw ctx: *mut c_void via submit_callback, while both XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged (networking.rs:132) and XNetworkingUnregisterConnectivityHintChanged (networking.rs:692) remain unconditional true no-ops. On any non-immediate queue (manual, serialized, thread-pool, or null process queue), a title that calls Unregister(token, true) and frees ctx can have the queued or concurrently executing callback dereference the freed ctx. Unlike XCL's notify_association / XUserUnregisterForDeviceAssociationChanged pattern (xgameruntime/mod.rs:908-981) that the PR cites, there is no per-token CallState::{Queued, Running, Done} + Condvar tracking to cancel queued callbacks, wait when wait == true, or report false when wait == false with a callback in flight. (2) Swallowed queue failures: notify_initial (networking.rs:73-80) logs hr < 0 (e.g., E_ABORT on a terminated queue or E_INVALIDARG when queue is null with no process task queue) and drops the error, so both register calls still return S_OK with a token even though the initial callback will never fire. (3) Test coverage gap: register_fires_an_initial_callback only exercises MODE_IMMEDIATE, where the callback runs synchronously inside Register, so neither post-unregister cancellation nor failed-submit handling is tested. (Also note the #1828 null-callback test overlap noted in #1607 triage.)
performance: negligible (one small heap allocation and one queued callback per registration)
verdict: not yet: unregistration leaves queued/running initial callbacks uncanceled (use-after-free hazard on ctx on non-immediate queues — track and cancel/wait per token like XUserUnregisterForDeviceAssociationChanged in xgameruntime/mod.rs:908-981), failed submit_callback results should be propagated rather than returning S_OK (with manual-queue unregister and failed-submit tests), and a runtime PR needs a title run: past the loading screen (#3041)
hardware / tool and model: NVIDIA GeForce RTX 3080 (driver 32.0.16.2140), AMD Ryzen 7 5800X3D, Windows 11 (10.0.26300.0), Rust 1.98.1-x86_64-pc-windows-msvc, DXC 1.9.0.5512 (VulkanSDK, no dxil.dll) / Antigravity, Gemini 4 Neon

<!-- greyfinch-sync:ivall/xcl:comment:7360860155 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7360860155). Originally posted by [grathepic](https://github.com/grathepic) on 2026-12-02T22:33:43Z. --- merge-check base: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a head: e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1 merge: clean (`git diff --check origin/main..HEAD` clean) build: `cargo +1.98.1-x86_64-pc-windows-msvc build --offline --locked --workspace` -> ok tests: `cargo +1.98.1-x86_64-pc-windows-msvc test --offline --locked --workspace --no-fail-fast -- --test-threads=4` (with `XCL_DXC_DIR=C:\VulkanSDK\1.4.363.0\Bin`, `XCL_SAMPLE_*` unset) -> 3007 passed, 0 failed, 52 ignored across 44 harnesses; SKIPPED: 27 notices (22 `no wave64`, 2 `no heap windows`, 1 `no GPU_UPLOAD heaps`, 1 `no dxil.dll`, 1 `cannot disable the driver cache (Windows Developer Mode required)`); failing: none. New test `hle::xgameruntime::networking::tests::register_fires_an_initial_callback` ran and passed. title run: none (no retail title run on this machine; note this PR changes runtime code outside tests and the earlier `merge-check` also lacks a `title run:` past the loading screen) review: Full diff read (`+104/-9`, `crates/xcl/src/hle/xgameruntime/networking.rs`). Blocking findings: (1) Use-after-free hazard on unregistration: `XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged` (`networking.rs:118-130`) and `XNetworkingRegisterConnectivityHintChanged` (`networking.rs:676-690`) now queue asynchronous `InitialNotification<T>` callbacks holding a raw `ctx: *mut c_void` via `submit_callback`, while both `XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged` (`networking.rs:132`) and `XNetworkingUnregisterConnectivityHintChanged` (`networking.rs:692`) remain unconditional `true` no-ops. On any non-immediate queue (manual, serialized, thread-pool, or `null` process queue), a title that calls `Unregister(token, true)` and frees `ctx` can have the queued or concurrently executing callback dereference the freed `ctx`. Unlike XCL's `notify_association` / `XUserUnregisterForDeviceAssociationChanged` pattern (`xgameruntime/mod.rs:908-981`) that the PR cites, there is no per-token `CallState::{Queued, Running, Done}` + `Condvar` tracking to cancel queued callbacks, wait when `wait == true`, or report `false` when `wait == false` with a callback in flight. (2) Swallowed queue failures: `notify_initial` (`networking.rs:73-80`) logs `hr < 0` (e.g., `E_ABORT` on a terminated queue or `E_INVALIDARG` when `queue` is null with no process task queue) and drops the error, so both register calls still return `S_OK` with a token even though the initial callback will never fire. (3) Test coverage gap: `register_fires_an_initial_callback` only exercises `MODE_IMMEDIATE`, where the callback runs synchronously inside `Register`, so neither post-unregister cancellation nor failed-submit handling is tested. (Also note the `#1828` null-callback test overlap noted in `#1607` triage.) performance: negligible (one small heap allocation and one queued callback per registration) verdict: not yet: unregistration leaves queued/running initial callbacks uncanceled (use-after-free hazard on `ctx` on non-immediate queues — track and cancel/wait per token like `XUserUnregisterForDeviceAssociationChanged` in `xgameruntime/mod.rs:908-981`), failed `submit_callback` results should be propagated rather than returning `S_OK` (with manual-queue unregister and failed-submit tests), and a runtime PR needs a `title run:` past the loading screen (#3041) hardware / tool and model: NVIDIA GeForce RTX 3080 (driver 32.0.16.2140), AMD Ryzen 7 5800X3D, Windows 11 (10.0.26300.0), Rust 1.98.1-x86_64-pc-windows-msvc, DXC 1.9.0.5512 (VulkanSDK, no dxil.dll) / Antigravity, Gemini 4 Neon
Pipodi commented 2026-12-02 23:51:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Pipodi on 2026-12-02T23:51:37Z.


merge-check
base: 078358a058
head: e2a4b1d319
merge: clean (git merge --no-ff onto 078358a0, merge eca96dfa; xgameruntime/networking.rs +104/-9)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 0 failed, 52 ignored; failing: none (SKIPPED 25: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache). The new hle::xgameruntime::networking::tests::register_fires_an_initial_callback passes.
title run: retail title on NVIDIA GeForce RTX 4090, no save, into the in-engine intro cutscenes, 420 s (ended by XCL_RUN_SECONDS), same env and frame presses as a run of main 078358a0 right after it. This PR: 336 s in the in-engine cutscenes (from the first 2 s window with over 5000 dispatches, at 95 s, to the end), 2.13 presents/s there, 2586 presents in the run, 0 device removals, 0 crashes (exit 0x0), peak video memory 21352 MB local, peak private 44 GB. Main 078358a0: 334 s in the cutscenes (from 101 s), 2.03 presents/s, 2614 presents, 0 removals, exit 0x0, 21546 MB local, 43.6 GB. The first PR attempt was stopped by the warm gate (shader cache cold for the new binary), then one untimed warm-up run (exit 0x0) before the measured one. The log does not show whether the title registers either callback (nothing is logged when the initial callback is queued), so this run checks for regressions, not the fix. Title binary = merge result + local scripted-press commits (input only) and two local log-only diagnostics, the same stack as the main run.
review: read the whole diff, submit_callback/XTaskQueueSubmitCallback and the device-association callbacks in xgameruntime/mod.rs. 1) Blocking, agreeing with the second check: both register functions now queue a callback that holds the title's ctx, but XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged and XNetworkingUnregisterConnectivityHintChanged stay true no-ops. On any queue that does not run the completion port inline (a manual queue the title dispatches later, a thread-pool queue, the process queue), a title that unregisters and frees ctx before the callback runs gets it called with a freed ctx; with wait == true a running callback is not waited for either. XCL already keeps the opposite contract for the same kind of token in XUserUnregisterForDeviceAssociationChanged ("No callback of token runs after this: one still queued is canceled (the title may free its context as soon as the call returns), and with wait a running one is waited for"), with CallState Queued/Running/Done; the same for these two tokens (and a test on a manual queue: register, unregister, dispatch, no call) would fix it. Before this PR no callback was ever queued, so this is new exposure, though narrow: a title would have to unregister before its queue runs the initial callback. 2) Minor: when the callback cannot be queued (E_ABORT on a terminated queue), the register still returns S_OK with a token and only logs a warning; the record is freed, so no leak. 3) The callback cast and record lifetime are right: the record is freed in the call whether or not it is canceled, and connectivity_hint_changed_call passes a pointer to a hint that lives for the call. The test runs on MODE_IMMEDIATE only.
performance: none: one small allocation and one queued callback per registration, which a title makes once; nothing per frame. Presents and memory in the runs above are within the spread between runs of the same build here.
verdict: not yet: unregistering must cancel a still-queued initial callback and wait for a running one when wait is true, as XUserUnregisterForDeviceAssociationChanged does, with a test on a non-immediate queue. The title run shows no regression on NVIDIA.
hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0, debug (tests) / release (title runs); Claude Code, Claude Opus 5.5

<!-- greyfinch-sync:ivall/xcl:comment:7362511461 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1237#issuecomment-7362511461). Originally posted by [Pipodi](https://github.com/Pipodi) on 2026-12-02T23:51:37Z. --- merge-check base: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a head: e2a4b1d3190260b7a8799b916b5de5f7a5b69ab1 merge: clean (`git merge --no-ff` onto 078358a0, merge eca96dfa; xgameruntime/networking.rs +104/-9) build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 0 failed, 52 ignored; failing: none (SKIPPED 25: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache). The new hle::xgameruntime::networking::tests::register_fires_an_initial_callback passes. title run: retail title on NVIDIA GeForce RTX 4090, no save, into the in-engine intro cutscenes, 420 s (ended by XCL_RUN_SECONDS), same env and frame presses as a run of main 078358a0 right after it. This PR: 336 s in the in-engine cutscenes (from the first 2 s window with over 5000 dispatches, at 95 s, to the end), 2.13 presents/s there, 2586 presents in the run, 0 device removals, 0 crashes (exit 0x0), peak video memory 21352 MB local, peak private 44 GB. Main 078358a0: 334 s in the cutscenes (from 101 s), 2.03 presents/s, 2614 presents, 0 removals, exit 0x0, 21546 MB local, 43.6 GB. The first PR attempt was stopped by the warm gate (shader cache cold for the new binary), then one untimed warm-up run (exit 0x0) before the measured one. The log does not show whether the title registers either callback (nothing is logged when the initial callback is queued), so this run checks for regressions, not the fix. Title binary = merge result + local scripted-press commits (input only) and two local log-only diagnostics, the same stack as the main run. review: read the whole diff, `submit_callback`/`XTaskQueueSubmitCallback` and the device-association callbacks in xgameruntime/mod.rs. 1) Blocking, agreeing with the second check: both register functions now queue a callback that holds the title's `ctx`, but `XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged` and `XNetworkingUnregisterConnectivityHintChanged` stay `true` no-ops. On any queue that does not run the completion port inline (a manual queue the title dispatches later, a thread-pool queue, the process queue), a title that unregisters and frees `ctx` before the callback runs gets it called with a freed `ctx`; with `wait == true` a running callback is not waited for either. XCL already keeps the opposite contract for the same kind of token in `XUserUnregisterForDeviceAssociationChanged` ("No callback of `token` runs after this: one still queued is canceled (the title may free its context as soon as the call returns), and with `wait` a running one is waited for"), with `CallState` Queued/Running/Done; the same for these two tokens (and a test on a manual queue: register, unregister, dispatch, no call) would fix it. Before this PR no callback was ever queued, so this is new exposure, though narrow: a title would have to unregister before its queue runs the initial callback. 2) Minor: when the callback cannot be queued (`E_ABORT` on a terminated queue), the register still returns `S_OK` with a token and only logs a warning; the record is freed, so no leak. 3) The callback cast and record lifetime are right: the record is freed in the call whether or not it is canceled, and `connectivity_hint_changed_call` passes a pointer to a hint that lives for the call. The test runs on `MODE_IMMEDIATE` only. performance: none: one small allocation and one queued callback per registration, which a title makes once; nothing per frame. Presents and memory in the runs above are within the spread between runs of the same build here. verdict: not yet: unregistering must cancel a still-queued initial callback and wait for a running one when `wait` is true, as `XUserUnregisterForDeviceAssociationChanged` does, with a test on a non-immediate queue. The title run shows no regression on NVIDIA. hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0, debug (tests) / release (title runs); Claude Code, Claude Opus 5.5
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1237:upstream-pr/1237'
git switch 'upstream-pr/1237'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1237'
git switch 'upstream-pr/1237'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1237'
git switch 'upstream-pr/1237'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1237'
git switch 'main'
git merge --squash 'upstream-pr/1237'
git switch 'main'
git merge --ff-only 'upstream-pr/1237'
git switch 'main'
git merge 'upstream-pr/1237'
git push origin 'main'
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!1227
No description provided.