gdk rt: XAsyncGetStatus(wait) waits for the completion callback, as the PC runtime does #210
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!210
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/210/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@QuentinDanblon on GitHub · 2026-11-23 02:04 UTC · original
QuentinDanblon:fix/xasync-wait→main· +379 −22 · 3 files · 3 commits · closed without mergingLibrary / area: compat-common,
gdk/rt.rs(emulated XAsync)Exports changed (exports.txt rows): none
Source of the behaviour: measured on the PC
xgameruntime.dll10.0.26100.9656 (System32, loaded directly, thread-pool queue). This is the PC runtime, not a console. The result matches the design of libHttpClient's AsyncLib (MIT), which I used to understand the measurements; no code taken from it.One topic: when
XAsyncGetStatus(wait = true)returns.rt.rsonly, +27 / -20, plus a 208-line test file.What was wrong
get_status(wait)looped on the status.complete()sets the status first, then queues the completion callback, and only notifies after the callback. So:XAsyncCompleteof a call with a result returned at once, while the callback was still running. The PC runtime returns after the callback has returned.complete()wrote the block (mark) after the status was visible, with the provider'sCleanupin between. A waiter could return and then see the block change.Measurements (12 runs per case, callback sleeps 60 ms)
ad24144E_ABORTfrom theCancelop, then waitCleanupsleeps 200 ms, wait during itCleanup, block unchanged afterwards, 5 / 5The row about waiting from inside the callback is a consequence of the fourth and I left it faithful: a title cannot depend on a hang. If you would rather return there, say so and I will add the exception.
Manual completion port (added after your question): the PC runtime never dispatches from inside the wait. A thread that waits on a call with a result and is the only one pumping the completion port blocks there on the PC runtime, and it already blocks on
mainwhen the wait started while the call was pending. This PR changes only the "arrives after completion" row, to what the PC runtime does.The change
AStategets asignaledflag, raised after the completion callback (or at completion when there is none, or when the queue is invalid).get_status(wait)waits for it.Arc::ptr_eq). Before, the removal ran after the callback, so a callback that began a new call on the same block lost the new state.complete()reads the callback pointer inside the same critical section and does not touch the block afterwards.Cost: one atomic load per
get_status(wait), one extra short lock per completion. No change on the non-waiting path.Tests
tests/gdk_xasync_wait.rs, six cases through the interface slots:ad24144wait_on_a_completed_call_with_a_result_returns_after_the_callbackblock_is_not_written_after_wait_returnswait_on_a_completed_call_without_a_result_does_not_wait_for_the_callbackwait_started_while_pending_returns_after_the_callbackwait_does_not_pump_a_manual_completion_queuewait_on_a_completed_call_without_a_result_leaves_the_callback_queuedcargo test -p compat-common --release --no-fail-fastonad24144plus the first commit: 233 passed, 1 failed, 11 ignored. After the second commit (tests only) I reran the test file alone: 6 passed, 5 runs out of 5. The failure isgdk_multi_dll, which did not get as far as running: its nestedcargo builddrops everyTOMBOX_*variable, this machine has no Windows SDK DXC outsideTOMBOX_DXC_DIR, andshaders/query_accum.dxilis not in the tree, so thed3d12_xsbuild script stops. Not related to this change. With the two-line fix of #212 on top,gdk_multi_dllpasses here with this PR'srt.rs(1 passed).Also run with the conformance scenarios of the old #48 on top (not in this PR, I will resubmit them separately as you asked): the default set passes 8 times out of 8, and
verify_wait_for_completion, run alone 20 times, goes from 16 / 20 to 20 / 20.Not in this PR
Measured in passing, left alone because it is a different topic and it changes what a provider must do: after
XAsyncCancel, the PC runtime leaves the call pending until the provider completes it (statusE_PENDINGright after a cancel that the provider ignores, then the provider's own result).rt.rscompletes the call itself withE_ABORT. That is whyverify_cancellationand the twoverify_cleanup_waits_for_workscenarios still differ.No comment lines added (PR gate: 2 files checked, 0 problems).
cargo test -p compat-common --release: 233 passed;gdk_multi_dllcould not build on this machine (see above)missingwith a note🤖 Generated with Claude Code
@omonkeyz on GitHub · 2026-11-23 02:10 UTC · original
Thanks, very thorough measurements. Gate clean, and compat-common passes here, including the new gdk_xasync_wait test. It's waiting on a go/no-go from the graphics lead, because it changes XAsync timing for every title and we're in the middle of a Trackmania hang investigation. One question: your measurements use a thread-pool queue. Do you know how the PC runtime behaves when the completion callback goes to a manual-dispatch queue that the waiting thread itself pumps? With this change, that case would block in XAsyncGetStatus(wait). A row for it (measured, or from the AsyncLib design) would help the review.
@omonkeyz on GitHub · 2026-11-23 02:11 UTC · original
Update from the graphics lead: this is on hold until after the next release is cut. It then gets a Trackmania A/B run. One measurement is needed before it can merge: on the PC runtime, call XAsyncGetStatus(wait = true) on the thread that pumps the call's manual-dispatch completion queue. Use a call that has a result, and complete it from another thread. If the PC runtime deadlocks there too, staying faithful is fine. If it returns, this PR must not introduce that deadlock, for example by dispatching or skipping the pending callback for the waiting thread. Please add that case to your table and to tests/gdk_xasync_wait.rs.
@QuentinDanblon on GitHub · 2026-11-23 02:15 UTC · original
One more effect, found while rechecking the conformance scenarios for #211: on
ad24144,verify_get_async_status_no_deadlockdoes not finish (5 runs out of 5, 40 s timeout). It rerunsXAsyncRunon the same block as soon as the status is final, 300 times, with no callback. The old removal incomplete()ran after the status was visible and was not checked against the state, so it could remove the state of the next call on that block; the scheduled work then finds no state and the block staysE_PENDING. With this PR'sArc::ptr_eqcheck it passes 10 runs out of 10. The scenario passes on the PC runtime.With this
rt.rs, threeDIFFERSentries of #211 pass: that one,verify_wait_for_completionandverify_no_write_after_get_status_race.@QuentinDanblon on GitHub · 2026-11-23 02:21 UTC · original
Measured, and understood for the hold until after the release.
PC
xgameruntime.dll10.0.26100.9656, queue with a thread-pool work port and a manual completion port that nobody dispatches, the wait on its own thread with a 1.5 s watchdog, then the test thread dispatches the port. 5 runs per case:ad24144So the PC runtime deadlocks there too: the wait never dispatches, and a thread that is the only pump of the completion port and waits on a call with a result stays blocked. For your exact case (completed from another thread while the wait is in progress)
mainalready blocks today, so this PR does not introduce it. The only row this PR changes is the second one.Added to the table in the description and to
tests/gdk_xasync_wait.rs(0908466, tests only):wait_does_not_pump_a_manual_completion_queuecovers both halves with a result, andwait_on_a_completed_call_without_a_result_leaves_the_callback_queuedthe last row. Onmainthe first one fails on its "after completion" half; with this PR the file passes 6 / 6, 5 runs out of 5.For the Trackmania investigation, in case it helps: on
main, a wait that starts while a call is pending already needs the completion port to be dispatched by another thread, whatever the result size. If the title waits on the thread that pumps a manual completion port, that blocks with or without this PR.@omonkeyz on GitHub · 2026-11-23 02:22 UTC · original
Thanks, that answers it. The PC runtime also blocks when the waiting thread is the only pump of the manual completion port, so the faithful behaviour is fine, and the new tests cover it. The fix to the state removal (Arc::ptr_eq) for verify_get_async_status_no_deadlock is noted too. This stays on hold only for the Trackmania A/B, which runs now that the release is cut.
@QuentinDanblon on GitHub · 2026-11-23 10:51 UTC · original
Rebased onto
de1e1da(r32j), the branch conflicted with it. Same two commits, nowa81ff11andcb189a9. Nothing else changed.The conflict was one block in
rt.rs: r32j splitcompleteintocompleteandcomplete_state, and this PR rewrites the body of that function. I kept the split of r32j with the body of this PR.On
cb189a9, RTX 5090 PC, Windows 11:cargo test -p compat-common --release --test gdk_xasync_wait: 3 runs, 6 passed each.--test gdk_xtaskqueue_conformance: 3 runs, 61 passed each.--test gdk_xtaskqueue_conformance_real(PCxgameruntime.dll10.0.26100.9656): 61 passed.--lib: 3 runs, 147 passed each.pr_gate.py --base origin/main: 0 problems.Not run here:
cargo check --workspacestops on this PC at the build scripts ofconnectedstorageservice_proxystubandgamecorecomproxy(their localdata/*.bininputs are missing). CI covers it.If your Trackmania A/B was done on the old head
0908466, the change is the same, applied to the function that r32j namedcomplete_state.This PR and #271 change the same function (
complete_state), so they conflict with each other (git merge-tree). #270 does not conflict with this one. I will rebase whichever of #210 and #271 is merged second.@omonkeyz on GitHub · 2026-11-23 10:54 UTC · original
Thanks for the rebase. We're bundling this with #270 and #271 for one full-boot Trackmania gate in the next release. On top of those two, a81ff11 conflicts in crates/compat/compat-common/src/gdk/rt.rs, because #271 changes the same completion path. Could you rebase this branch onto #271's head, so the three stack in order (#270, #271, #210)? Then please run the gdk_xasync_wait and conformance tests again on that stack. I'd rather not resolve a conflict in the completion logic myself.
@QuentinDanblon on GitHub · 2026-11-23 11:04 UTC · original
Done. This branch now sits on #271's head (
4299f39): #271's commit, then0611df3and9ebd0e2(the same two changes as before). #270 is not in the branch; it merges on top without conflict.The conflict was in
complete_state, three blocks. Resolution, so you can check it without redoing it:markand the removal from the state map (withArc::ptr_eq) happen under the status lock, and the end of the call issignal()(setssignaled, thennotify_all) instead ofcv.notify_all().after_callback = !keep && callback.is_some() && in_begin; Cleanup runs at once only when!keep && !after_callback; otherwise it runs in the completion job after the callback, or in theQueued::Invalidarm.after_callback, thensignal(). So aXAsyncGetStatus(wait = true)that returns has seen the Cleanup of a call completed during Begin.Tests, RTX 5090 PC, Windows 11, release:
Stack #270 + #271 + #210 (this branch with #270's head merged in, local only):
--test gdk_xasync_wait: 3 runs, 6 passed each.--test gdk_xtaskqueue_conformance: 3 runs, 64 passed each.--test gdk_xtaskqueue_conformance_real(PCxgameruntime.dll10.0.26100.9656): 64 passed.--lib: 3 runs, 149 passed each.This branch alone (#271 + #210):
gdk_xasync_wait6 passed,gdk_xtaskqueue_conformance63 passed,gdk_xtaskqueue_conformance_real63 passed,--lib147 passed.pr_gate.py --base origin/main: 0 problems.The stack was tested on
de1e1da.mainhas since moved to r32k (2d4cbd5);git merge-treeshows no conflict between it and each of #270, #271 and this branch. I did not rerun the tests on r32k.Once #271 is merged, this PR's diff shows only its two commits.
@omonkeyz on GitHub · 2026-11-23 13:45 UTC · original
Applied locally on main with your authorship kept (cherry-picked,
139f94c); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.@kiwe147 on GitHub · 2026-11-23 19:15 UTC · original
Tested head
9ebd0e2adb, applied withgit apply(whitespace ignored, the line endings of my checkout differ) onmainf89e410, together with #227 (one tree; the PRs touch different files). It applied without conflicts and built.Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, NVIDIA GeForce RTX 3080 (driver 621.24), MSVC, Rust 1.91.1.
cargo test -p compat-commonmain:history_frames_are_compressed_and_clips_are_h264returns 0x8007007F on this machine)No new failure against
mainf89e410in any of these. This is one combined tree, not a run of this PR alone.AI-assisted: yes (Claude Code)
@omonkeyz on GitHub · 2026-11-25 13:09 UTC · original
Applied on main in
139f94c(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed