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

Closed
tiagonleal wants to merge 1 commit from upstream-pr/3172 into main
tiagonleal commented 2026-11-28 15:53:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-28T15:53:39Z.


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; #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

<!-- greyfinch-sync:ivall/xcl:issue:5541964709 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3172). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-28T15:53:39Z. --- 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; #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](https://claude.com/claude-code)
throny commented 2026-11-28 23:48:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-28T23:48:24Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7247675945 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3172#issuecomment-7247675945). Originally posted by [throny](https://github.com/throny) on 2026-11-28T23:48:24Z. --- <!-- xcl-1607-hint:D154 --> 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 commented 2026-11-29 11:04:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-29T11:04:59Z.


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
<!-- greyfinch-sync:ivall/xcl:comment:7254867713 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3172#issuecomment-7254867713). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-29T11:04:59Z. --- 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

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3172
No description provided.