Repository navigation
Runtime: a game thread that ends the run no longer exits the host mid-line (TEST-874) - #4052
undeadhuman37 wants to merge 1 commit into
Conversation
…-line (TEST-874) end_run read g_running after setting g_done. If the thread was preempted between the two, run_entry returned, cleared g_running and the host went on printing; the game thread then saw false and called ExitProcess with the game's exit code, which ended gta6rt partway through "game exited with code 0". With stdout and stderr on one pipe (CMake's execute_process in check_game_dir.cmake) and ctest -j, run_tiny_game_dir failed intermittently. g_running is now read before g_done is set, so the thread that ends the run always parks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Overlap note: #4043 (opened a few minutes earlier) has the same change to I measured that code on Windows 11, MSVC 19.44 (results on #4043): truncated AI-assisted (Claude). |
0xTehuti
left a comment
There was a problem hiding this comment.
Tested b35b18fc on Windows 11 Pro build 26100, MSVC 19.44 (VS 2022 Community), Ninja 1.13, CMake 4.4.
1. Concurrency Stress Test Verification (PASS)
Ran ctest -j 4 -R "run_tiny|process" --output-on-failure --repeat until-fail:20:
- Result: 12/12 tests passed (100%), 0 failures across all 20 iterations (2.22s real time).
- Tests covered:
process_cmdlinerun_tiny_asyncrun_tiny_gdk_loadrun_tiny_bundled_loadrun_tiny_gamerun_tiny_game_console_pathsrun_tiny_game_exit_coderun_tiny_game_fixedrun_tiny_game_fixed_exit_coderun_tiny_game_tlsrun_tiny_game_ehrun_tiny_game_dir
Capturing const bool running = g_running; before signaling SetEvent(g_done) ensures game threads that entered during active run cleanly park on Sleep(INFINITE) and do not prematurely invoke ExitProcess while the host's run_entry is flushing its final messages.
Resolves TEST-874. LGTM.
|
Closing as a duplicate of #4043 (@AAyberkU), which was opened five minutes earlier with the same |
|
Tested b35b18f on Windows 11 (26200), MSVC (VS 2022 Build Tools) RelWithDebInfo build of this head (CPU only, no GPU involved): Run at -j 4 to keep the load on this machine down, not the -j 8 from the description. AI-assisted. |
Flyander
left a comment
There was a problem hiding this comment.
The �nd_run hunk here is functionally identical to #4043: both read g_running before SetEvent(g_done) and park based on that snapshot. #4043 also adds the regression test in process_cmdline_test.cpp and has already been reviewed. Please coordinate with that PR or consolidate the fix so the same change is not kept open twice. I found no distinct code change in this diff.
TEST-874 (claim). Depends on: nothing open. Builds on @tedin7's notes in the claim thread.
Cause
run_tiny_game_dirfailed underctest -jbecause gta6rt was killed partway through its last line. The failing output endsgame exited w(org,game exite, ...), and the exit code is still 0.The race is in
end_run(runtime/shims/process.cpp). A game thread that callsexit/ExitProcess:g_exit_codeandg_done;g_runningto decide whether to park.If the thread is preempted between those two steps, the following happens:
run_entrywakes, clearsg_runningand returns.game exited with code 0.false, takes the "run already over" branch and callsExitProcess(g_exit_code), which ends the host mid-line.check_game_dir.cmakecaptures stdout and stderr into one variable and checks thegame exited with code 0line, so the missing tail fails the test. The other tiny-game tests don't check that line.Fix
end_runreadsg_runningbefore it setsg_done, so the thread that ends the run always parks. The atexit case (game code callingexitafterrun_entryreturned) still seesfalseand exits with the game's code, as before.How it was found and checked (RTX 4070 SUPER, driver 621.01, Windows 11, MSVC 14.44)
main:ctest -j 8 -R "run_tiny|winhttp" --repeat until-fail:30failed within one or two rounds.gta6rt --game-dir . --run tiny_game.exe -- hello 42 game-file, with stdout and stderr on one pipe, cut the last line in about 3 per 1,000 runs. With separate pipes, none of 400 did.fflushsucceeded, the stdout handle was the same object before and after the run, and the probe's own log afterprintfwas never written. So the process ended insideprintf, which points to another thread'sExitProcess.ctest -j 8 -R "run_tiny|gta6rt_" --repeat until-fail:60passes all 60 rounds.ctest: 146/146 passed.compileallandmake_game.py --help: OK.Not covered
winhttp_offlinefailed once in my first-j 8runs (every handle reports HANDLE_CLOSING once,closing the request inside the callback reports HANDLE_CLOSING once). It doesn't use gta6rt, so it's a separate race in the WinHTTP shim's close callbacks; I'm posting it as a finding rather than mixing it in here. It passed 60 rounds afterwards, so it's rarer.AI-assisted (Claude Code). No game files used.
🤖 Generated with Claude Code