Repository navigation
XGameRuntime: track task queue waiters safely and avoid terminate races - #315
Michael-Glaser wants to merge 1 commit into
Conversation
|
A Windows run for this draft, since Not tested says it has not been built or run on Windows yet: Tested
Not tested
AI use: Claude Code with Claude Opus 5.5 ran the build and tests and wrote this comment; the numbers come from those runs. |
0cdf319 to
04b8042
Compare
|
Thanks @regiumlepidi! Rebased onto main (a6f5f7a, commit 04b8042) and replaced the timing loop with a deterministic dispatch_due_timed pop-vs-terminate test that holds Terminate right between pop() and submit_now() so it reliably reproduces the dropped callback without the fix. |
|
Updated-head Windows validation: Tested
Not tested AI use |
XTaskQueueRegisterWaiter handed the raw Box<Waiter> pointer out as the registration token and wrote (*w).wait after RegisterWaitForSingleObject had already armed waiter_fired. XTaskQueueUnregisterWaiter blindly cast any token back to Box<Waiter> (double-free on duplicate or bogus tokens) and called UnregisterWaitEx(..., INVALID_HANDLE_VALUE) synchronously (deadlocking when called from a MODE_IMMEDIATE waiter callback). XTaskQueueTerminate also left waiters registered and could race with timer() between popping a due item and submit_now, silently dropping the canceled callback. Track waiters in a token-keyed map with Arc<Waiter>, hold the wait-handle lock across RegisterWaitForSingleObject, detect self-unregister via thread-local IN_WAITER and defer blocking UnregisterWaitEx to the worker pool, unregister a queue's remaining waiters during XTaskQueueTerminate, and hold an inflight handoff guard across timer()'s pop-to-submit_now transition under the existing timer -> q.state lock order. Assisted-by: Antigravity (Gemini 4 Neon)
04b8042 to
3a684ef
Compare
|
Thanks @WebIdentity1 for validating |
|
Regression run of Against the limits in CONTRIBUTING.md: 101 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
Fixes raw-pointer waiter double-free,
MODE_IMMEDIATEself-unregister deadlock, leaked waiters onXTaskQueueTerminate, and atimer()pop-vs-terminate race that dropped canceled delayed callbacks.What is in it
crates/xcl/src/hle/xgameruntime/taskqueue.rs: token-keyedArc<Waiter>map, lockedRegisterWaitForSingleObject, deferred worker-pool unregister on self-unregister, waiter cleanup on terminate,inflighthandoff guard intimer(), and unit tests.Tested
aarch64-apple-darwin, Rust 1.100.0):cargo check --offline --target x86_64-pc-windows-msvc --workspace --tests(0 errors, 0 new warnings).Not tested
cargo testandscripts/smoke.ps1not run yet.AI use