Repository navigation
fix(tests): end Windows test processes through libc before DLL detach - #6986
Conversation
On Windows a test that returns from main ends through exit and ExitProcess, which kills every other thread before the prx static destructors run at DLL_PROCESS_DETACH. Detached host threads (the driver's async log thread, libkernel's file watch thread, ...) die holding winpthreads and queue locks, and a destructor that then locks a mutex, waits for the dead logger or destroys a condition variable never returns: the test prints its last line and hangs until the CTest timeout (boykopovar#6791). Every test executable now wraps main on MinGW. After main returns the wrapper runs the executable's own exit handlers and static destructors (_cexit), as exit does today, flushes the streams and ends the process with LibcTerminate_nid_no_patch, the path the guest exit already takes. That flushes the driver log while its thread is alive and calls TerminateProcess, so no DLL_PROCESS_DETACH work runs after the threads are gone. The libc shutdown callbacks are not run, as on a plain return from main on Linux. A test that does not load libc.prx returns as before.
|
The current conventions check fails because the PR body is missing the template sections |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows run: i7-13700K, RTX 4080 (617.42) and Intel UHD 770 (101.6129), WinLibs GCC 15.2.0, Release. Tested #6986 (ea33174) merged onto main f643e61. guest_shader_link alone on the UHD 770, 15 runs, 60 s timeout
Full Failures that remain, all failing on plain main f643e61 too (checked by rerunning them there), so none come from this PR:
AI-assisted: yes (Claude Code) |
|
Thanks @johnmaia, that's very useful. The fiber import and |
Windows CI times out single tests at 120 s after they have already finished (#6791). It's not specific to any test:
agc_driver_pm4_ring_invalid,agc_interpolant_mapping,guest_shader_linkand others hit it, and a re-run moves it to another test.The cause is the exit path. A test returning from
mainends throughexit->ExitProcess, which kills every other thread and only then runs the prx DLLs' static destructors atDLL_PROCESS_DETACH. Detached host threads are still alive at that point (the driver's async log thread,AsyncLog.hpp:196; libkernel's file-watch and alarm threads), and they die holding locks. A destructor that then flushes the async log, locks one of those mutexes or destroys a condition variable (winpthreads'pthread_cond_destroywaits without a timeout) never returns. Linux doesn't see it, becauseexitruns destructors while the threads are still alive. That's also why tests that already callLibcRunShutdownbefore returning (the approach in #6925) still hang: the detached threads outlive it, and DLL detach still runs after they're gone.This wraps
mainfor every test executable on MinGW (LINKER:--wrap=maininadd_test_executable,cmake/WindowsTestExit.cpp). Aftermainreturns, the wrapper runs the executable's own exit handlers and static destructors (_cexit), flushes the streams and ends the process withLibcTerminate_nid_no_patch(the path guest exit already uses: end-flush, thenTerminateProcess). The driver log is flushed while its thread is alive, and noDLL_PROCESS_DETACHwork runs after the threads are gone. The libc shutdown callbacks are not run, matching a plain return frommainon Linux. A test that doesn't loadlibc.prxreturns as before. Linux and macOS are unchanged.It replaces the per-test approach in #6925, which becomes redundant but harmless.
Validation: I don't have a Windows machine, so this PR's Windows CI is also its first compile. I'll repeat the full Windows run several times and compare the timeout count with main (about 5 timeouts in 11 runs on 10-16).
Refs #6791, #6925.