runtime: wait for an ended mesh request writer before the exit drain #3885

Manually merged
github merged 1 commit from gh-pr/3883/head into gh-pr/3883/base 2026-12-02 19:24:26 +00:00
Owner

@⁠mumba17 on GitHub · 2026-12-02 19:03 UTC · original
mumba17:runtime/mesh-request-exit-wait → main · +44 −8 · 2 files · 1 commits · merged 2026-12-02 19:22 UTC

Fixes #3824 (the case #3856 does not cover).

Cause

drain_at_process_exit checked whether the writer thread was alive and, if it was, called flush() and returned 0. ExitProcess ends the other threads asynchronously, though. At DLL_PROCESS_DETACH the writer's handle can still read as alive, most often when the writer has not been scheduled yet: a fixture that exits right after its first slot 86 request. flush() then waits on idle_, which an ended writer never signals. It times out after the 2 s budget, nothing is written, and the fixture finds no req_*.m86.

#3856 handles a writer ended while holding lock_ whose handle has already signalled. This is the case where the handle has not signalled yet.

Change

  • src/startup_stubs/request_publisher.h: at process exit, wait (within the same timeout_ms) for the writer thread's handle to signal, then drain on the detaching thread through the existing locked or lock-free paths. If it does not signal in time, return 0 as before. The ordinary drain() (FreeLibrary with a live writer) is unchanged.
  • tests/startup_request_publisher_check.cpp: case 5 holds a live writer inside its first write and ends it with TerminateThread 100 ms after drain_at_process_exit(1000) starts. Both requests must be written by the exit writer, in order, in under 900 ms. Before the change it fails all three checks (0 written after the full timeout).

Evidence

Windows 11 build 26300, MSVC Debug (dev preset), WARP (Microsoft Basic Render Driver), RTX 3090 host. The first fixture launch of run_heap (startup_indirect_draw_indexed warp mesh, the environment from startup_indirect_mesh_cache_check.py) was looped with 24 busy processes on 12 logical CPUs.

Tree Runs without req_*.m86
main b68e954c 16/100, 21/100
this change 0/200

A local-only diagnostic (not in this PR) recorded the exit path. All 21 misses had: process terminating, writer alive at entry, queue not empty, flush() false after 2.0–2.1 s, writer ended afterwards, 0 written. With the change, 27 of the 200 runs hit that shape and were written. The wait for the writer averaged 7 ms (max 203 ms). The CI failure has the same timing: startup_indirect_mesh_cache_heap_warp failed at 2.71 s after a single fixture launch, while the whole test passes in 1.0–1.6 s.

Tests

  • ctest --preset dev --no-tests=error -j 1 --repeat until-fail:30 -R '^startup_indirect_mesh_(cache_heap(_wide)?_warp|lease_warp_dual(-trace)?)$' (the command from #3824): 4/4, 30 times each.
  • ctest --preset dev -j 1 -R "request_publisher|indirect_mesh|mesh86|mesh_request": 63/63.
  • startup_request_publisher_check --mutate inline still fails (negative control).
  • Both tests are already in the pr preset filter.

Reproduction claim on #3824 stays with triggered02. This PR is the fix only.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠mumba17** on GitHub · 2026-12-02 19:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3883) `mumba17:runtime/mesh-request-exit-wait` → `main` · +44 −8 · 2 files · 1 commits · merged 2026-12-02 19:22 UTC Fixes #3824 (the case #3856 does not cover). ### Cause `drain_at_process_exit` checked whether the writer thread was alive and, if it was, called `flush()` and returned 0. `ExitProcess` ends the other threads asynchronously, though. At `DLL_PROCESS_DETACH` the writer's handle can still read as alive, most often when the writer has not been scheduled yet: a fixture that exits right after its first slot 86 request. `flush()` then waits on `idle_`, which an ended writer never signals. It times out after the 2 s budget, nothing is written, and the fixture finds no `req_*.m86`. #3856 handles a writer ended while holding `lock_` whose handle has already signalled. This is the case where the handle has not signalled yet. ### Change - `src/startup_stubs/request_publisher.h`: at process exit, wait (within the same `timeout_ms`) for the writer thread's handle to signal, then drain on the detaching thread through the existing locked or lock-free paths. If it does not signal in time, return 0 as before. The ordinary `drain()` (FreeLibrary with a live writer) is unchanged. - `tests/startup_request_publisher_check.cpp`: case 5 holds a live writer inside its first write and ends it with `TerminateThread` 100 ms after `drain_at_process_exit(1000)` starts. Both requests must be written by the exit writer, in order, in under 900 ms. Before the change it fails all three checks (0 written after the full timeout). ### Evidence Windows 11 build 26300, MSVC Debug (`dev` preset), WARP (Microsoft Basic Render Driver), RTX 3090 host. The first fixture launch of `run_heap` (`startup_indirect_draw_indexed warp mesh`, the environment from `startup_indirect_mesh_cache_check.py`) was looped with 24 busy processes on 12 logical CPUs. | Tree | Runs without `req_*.m86` | |---|---| | main `b68e954c` | 16/100, 21/100 | | this change | 0/200 | A local-only diagnostic (not in this PR) recorded the exit path. All 21 misses had: process terminating, writer alive at entry, queue not empty, `flush()` false after 2.0–2.1 s, writer ended afterwards, 0 written. With the change, 27 of the 200 runs hit that shape and were written. The wait for the writer averaged 7 ms (max 203 ms). The CI failure has the same timing: `startup_indirect_mesh_cache_heap_warp` failed at 2.71 s after a single fixture launch, while the whole test passes in 1.0–1.6 s. ### Tests - `ctest --preset dev --no-tests=error -j 1 --repeat until-fail:30 -R '^startup_indirect_mesh_(cache_heap(_wide)?_warp|lease_warp_dual(-trace)?)$'` (the command from #3824): 4/4, 30 times each. - `ctest --preset dev -j 1 -R "request_publisher|indirect_mesh|mesh86|mesh_request"`: 63/63. - `startup_request_publisher_check --mutate inline` still fails (negative control). - Both tests are already in the `pr` preset filter. Reproduction claim on #3824 stays with triggered02. This PR is the fix only. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ExitProcess ends the other threads asynchronously, so at DLL_PROCESS_DETACH
the RequestPublisher writer's handle can still read as alive, most often when
the writer has not run yet (a fixture that exits right after its first slot 86
request). drain_at_process_exit then called flush(), which waits for an idle
signal that an ended writer never sends, timed out after 2 s and wrote nothing,
so the fixture found no req_*.m86 (#3822).

At process exit, wait (within the same timeout) for the writer thread's handle
to signal instead, then write the queue on the detaching thread as before.
Case 5 in startup_request_publisher_check ends a live writer 100 ms after the
drain starts; it fails on the old path and passes here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 19:24:24 +00:00
github manually merged commit 70e6107a23 into gh-pr/3883/base 2026-12-02 19:24:26 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 19:19 UTC · original · approved these changes

Reviewed 70e6107a. The process-exit path waits on the publisher thread within the existing deadline, then uses the existing locked or lock-free drain. The live FreeLibrary path is unchanged. Independent MSVC Debug on Windows 11 build 26300 ran ctest --preset dev --no-tests=error --output-on-failure -j 1 --repeat until-fail:5 -R '^startup_request_publisher(_inline_control)?$|^startup_indirect_mesh_(cache_heap(_wide)?_warp|lease_warp_dual(-trace)?)$'. All six tests passed five times each (30/30). The four WARP cases include both heap variants and both dual-lease paths. The publisher fixture exercises the delayed termination and the inline mutation remains covered.

**@⁠R0Y00** on GitHub · 2026-12-02 19:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3883#pullrequestreview-6157304777) · **approved these changes** Reviewed 70e6107a. The process-exit path waits on the publisher thread within the existing deadline, then uses the existing locked or lock-free drain. The live FreeLibrary path is unchanged. Independent MSVC Debug on Windows 11 build 26300 ran `ctest --preset dev --no-tests=error --output-on-failure -j 1 --repeat until-fail:5 -R '^startup_request_publisher(_inline_control)?$|^startup_indirect_mesh_(cache_heap(_wide)?_warp|lease_warp_dual(-trace)?)$'`. All six tests passed five times each (30/30). The four WARP cases include both heap variants and both dual-lease paths. The publisher fixture exercises the delayed termination and the inline mutation remains covered.
This discussion has been locked. Commenting is limited to contributors.
No description provided.