Repository navigation
Conversation
…one pair (RT-258) error_set_callback stored the context, then the callback, in two atomics, and error_report loaded them one after the other. A report between the two stores called the old callback with the new context. The pair now sits in one struct read and written under a mutex; the callback runs after the lock is released, so it may report or register again. xgameruntime_test switches the registration between two (callback, context) pairs 200,000 times on one thread while another reports, and each callback checks it got its own context. With main's shim 15-30% of reports were mixed (30115 of 186605, 34394 of 228053, 60756 of 201685 in three runs); with this, none. Found by @shdann. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Checked ec4ef29's shim against an extra race test, on Windows 11 with MSVC 19.52 (RelWithDebInfo, CPU only). It's the test from my closed duplicate #4002: two threads re-register pair A (callback A, context A) or pair B 200,000 times each, while two threads call
So the fix holds under contention. If you want the check in-tree, it's 40 lines in |
|
Independent Windows re-entry check of |
|
Tested ec4ef29 on Windows 11 (26200), MSVC (VS 2022 Build Tools) RelWithDebInfo, with RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1) each selected in turn ( No negative control run. AI-assisted. |
|
Hi! I'm a new contributor working with AI assistance on Windows with an NVIDIA RTX 4060. I noticed that RT-258 already has ongoing implementations, so I don't want to duplicate the fix. I was wondering whether a deterministic regression test for the XError callback/context race would be useful. The idea would be to control thread interleaving during callback registration and reporting, ensuring that a callback never receives the context belonging to another registration. I could also check reentrant callback behavior and potential deadlocks. Would you be interested in an additional test contribution? If so, should I work against this PR or coordinate a separate change? I would coordinate the work before submitting anything. No game files would be used. Thanks! |
|
Also tested No game files. AI-assisted (Claude Code). |
|
@traeb0n, a heads-up from a code read of
AI-assisted (Claude Code). cc @shayderrr |
Item: RT-258 (claim: #3796 (comment)), found by @shdann (finding).
What and why
error_set_callbackstored the context, then the callback, in two separate atomics, anderror_reportloaded them one after the other. With (cbA, ctxA) registered and another thread re-registering (cbB, ctxB), a report between the two stores calledcbA(hr, message, ctxB).The pair is now one
ErrorHandler {callback, context}, written and read under a mutex.error_reportcopies it under the lock and calls the callback after releasing it, so a callback may report or register again without deadlocking. Reports are rare (XCurl's errors), so the lock costs nothing that matters. I used a mutex rather than a 16-bytestd::atomic, which can needcx16on the clang-cl cross-build.Test
xgameruntime_test: one thread switches the registration between two (callback, context) pairs 200,000 times while the test thread reports, and each callback checks that it got its own context.Tested ec4ef29 on its base
mainaa2988c: Windows 11, i7-14700K, MSVC 14.44, RelWithDebInfo:ctest -E loader -j 4: 141/141 passed,xgameruntimeincluded.main'sxgameruntime.cppfails every time:AI-assisted (Claude Code).
🤖 Generated with Claude Code