Skip to content

fix(tests): end Windows test processes through libc before DLL detach - #6986

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/windows-test-exit-hang
Oct 17, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/windows-test-exit-hang

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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_link and others hit it, and a re-run moves it to another test.

The cause is the exit path. A test returning from main ends through exit -> ExitProcess, which kills every other thread and only then runs the prx DLLs' static destructors at DLL_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_destroy waits without a timeout) never returns. Linux doesn't see it, because exit runs destructors while the threads are still alive. That's also why tests that already call LibcRunShutdown before returning (the approach in #6925) still hang: the detached threads outlive it, and DLL detach still runs after they're gone.

This wraps main for every test executable on MinGW (LINKER:--wrap=main in add_test_executable, cmake/WindowsTestExit.cpp). After main returns, the wrapper runs the executable's own exit handlers and static destructors (_cexit), flushes the streams and ends the process with LibcTerminate_nid_no_patch (the path guest exit already uses: end-flush, then TerminateProcess). The driver log is flushed while its thread is alive, and no DLL_PROCESS_DETACH work runs after the threads are gone. The libc shutdown callbacks are not run, matching a plain return from main on Linux. A test that doesn't load libc.prx returns 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.

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.
@MarcZX10

Copy link
Copy Markdown
Contributor

The current conventions check fails because the PR body is missing the template sections What, Tested and Checklist. Please restore those headings and fill them in; the check reports all three as empty.

@github-actions

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 674 CMakeLists.txt
PR 1835 CMakeLists.txt
PR 5021 CMakeLists.txt
PR 6044 CMakeLists.txt
PR 6879 CMakeLists.txt

@oneandonlydean
oneandonlydean merged commit 9bf01db into boykopovar:main Oct 17, 2026
17 of 18 checks passed
@johnmaia

Copy link
Copy Markdown
Contributor

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

passed timed out
main 0c4e47016 (earlier run, same machine) 11 4
this PR 15 0

Full ctest -j4 --timeout 300, 1351 tests: no timeouts on either GPU. Without this PR, guest_shader_link timed out on the UHD in our full runs.

Failures that remain, all failing on plain main f643e61 too (checked by rerunning them there), so none come from this PR:

  • both GPUs: agc_driver_gpu_map_on_fiber ("started 1 host threads for its import instead of importing on the fiber's host stack"), guest_kqueue (0xc0000409)
  • UHD only: agc_driver_bindless_images, agc_driver_image_sint8, agc_driver_image_table, agc_driver_image_table_cache_bounds / _reuse (0xc0000409), agc_driver_sample_multisample_target ("sample 1 of pixel (0, 0) does not hold the stored color")

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator Author

Thanks @johnmaia, that's very useful. The fiber import and guest_kqueue failures are being looked at against #6993 and #6599/#6173. For the UHD-only 0xc0000409 group (agc_driver_bindless_images, agc_driver_image_sint8, agc_driver_image_table, agc_driver_image_table_cache_bounds / _reuse), I couldn't find an existing issue. Could you open one with the ctest --output-on-failure output for one of them on the UHD 770, plus the driver version and main commit? A debugger backtrace for the 0xc0000409 would help most, if you can get one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants