Skip to content

D3D12.X: end the title past the NtTerminateProcess hook - #3172

Closed
tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:d3d12x/end-watchdog-unhooked-terminate
Closed

tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:d3d12x/end-watchdog-unhooked-terminate

Conversation

@tiagonleal

@tiagonleal tiagonleal commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

A title run that ends through end_title (for example XCL_RUN_SECONDS, which scripts/smoke.ps1 uses) can stay alive forever instead of ending. Seen once today in about 85 smoke runs: the title ended at 60.4 s, the log's process ends line came exactly 15.0 s later, and 20 minutes on the process was still there, not responding, with 145 threads suspended. smoke.ps1 did not get its block and the queue behind it stood still.

end_title starts a watchdog that ends the process after 15 s "whatever happens", suspends every other thread, drains the GPU and terminates. Both terminate calls used TerminateProcess, which runs XCL's own NtTerminateProcess hook. With the other threads suspended, that hook formats and writes a log line (heap allocation, the log file mutex, an echo to stderr through std's stderr lock) and flushes the log. A suspended thread that holds one of those locks blocks the watchdog for good. The 15.0 s gap shows the watchdog was the caller (the drain was stuck), and 147 live threads show the kernel had not been asked to terminate yet. I found no issue or PR for this (searched "xcl-end-watchdog", "NtTerminateProcess hook", "process does not exit", "smoke.ps1 hangs").

What is in it

  • eh.rs: terminate_unhooked(code) calls the original NtTerminateProcess (or TerminateProcess when the hook is not installed). No allocation, no lock.
  • real.rs: end_title's watchdog and its final terminate use it. The two used-pipeline journal flushes the hook did now run before the threads are suspended, next to the log flush that was already there; with their writer thread suspended they could only time out.
  • Ordinary exits (ExitProcess, abort) still go through the hook and keep the process ends line. On the end_title path that line is gone.
  • Test eh::tests::terminate_unhooked_ends_past_a_suspended_stderr_holder: a child process installs the hook, suspends a thread that holds the stderr lock and terminates. It must end with the given code within 20 s.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug
  • The new test with the terminate routed through the hooked TerminateProcess: 0 passed, 1 failed ("the process did not end within 20 s"). With the change: passes.
  • cargo test -p xcl --lib eh:: -- --test-threads=2: 11 passed, 0 failed. cargo test -p xcl --test e2e -- --test-threads=1: 5 passed, 0 failed.
  • cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4, one run on head 2cc7279e: 2149 passed, 4 failed, 48 ignored (25 SKIPPED lines). The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0 to _3, which also fail on main here (10d27297: 2148 passed, 4 failed, 48 ignored; Recompiler: LDS ds_sub_u32 hides its negation from the driver (RTX 50 refuses it) #1919 fixes them).

Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e (Newer Retail Game), release builds in clean trees, main 10d27297 first, one run each, XCL_PREPARE=0, same DXIL cache. Both runs end through end_title, so the PR's run also shows the changed path ending the process normally.

main (10d27297):

xcl-smoke v1
commit: 10d272970f25b02b72ebe3c883d02d74d4d4763b
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 346 (PresentX 346)
presents per 2 s (last 3): 12 12 11
device removals: 0
crashes: 0
peak commit: 11041 MB

This PR (2cc7279e):

xcl-smoke v1
commit: 2cc7279e8dfddf25ae98603769f4cc81c6f22542
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 354 (PresentX 355)
presents per 2 s (last 3): 11 11 11
device removals: 0
crashes: 0
peak commit: 11063 MB

Not tested

  • The hang itself was seen once and not reproduced on purpose, so the fix is checked by the test and by reading the code, not against a repeat of the hang on a title.
  • Which lock blocked that run (stderr, the heap or the log file): the log does not say.
  • Why the GPU drain was stuck for 15 s in that run. This change only makes the process end when it is.
  • A pipeline first used in the last milliseconds before the threads are suspended can now be missing from used-pipelines.txt, because the journals are flushed slightly earlier.
  • AMD, Intel, Wine.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing.

🤖 Generated with Claude Code

end_title's 15 s watchdog promised that the process ends "whatever
happens", but it called TerminateProcess, which runs XCL's own
NtTerminateProcess hook with every other thread suspended. The hook
formats and writes a "process ends" line (heap allocation, the log file
mutex, then an echo to stderr through std's stderr lock), flushes the
log and the two used-pipeline journals. A suspended thread holding the
stderr lock, the log mutex or the heap lock blocks the watchdog forever.
end_title's own final TerminateProcess had the same exposure.

Observed once (release build, retail title, XCL_RUN_SECONDS=60): the
title ended at 60.4 s, the hook's "process ends" line came from the
watchdog exactly 15.0 s later (so the drain was stuck), and 20 minutes
on the process was still alive with 145 threads Suspended: the kernel
had never been asked to terminate. The file write had succeeded, so the
block was after it (stderr echo, heap, or a flush).

Both terminate calls now go through eh::terminate_unhooked, which calls
the original NtTerminateProcess (no allocation, no lock). The journal
flushes the hook did run before the threads are suspended; under
suspension their writer thread could not complete them anyway.

The test suspends a thread holding stderr with the hook installed: the
child process ends with the code given; through the hook it hangs.
@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2698 solves the same problem in a different way: #1607, group D154. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@tiagonleal

tiagonleal commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #2698, which was merged last night. It makes the same change: the end-of-run watchdog now ends the process through eh::end_process_now, which calls the real NtTerminateProcess and skips the hook, and its test holds the process heap in another thread. The hook is where my run was stuck too, so main already has what this PR was for.

  • Tiago

@tiagonleal tiagonleal closed this Nov 29, 2026
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.

2 participants