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

Merged
mumba17 merged 1 commit from upstream-pr/3883 into main 2026-12-02 19:22:18 +00:00
mumba17 commented 2026-12-02 19:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-02T19:03:02Z.


Fixes #3822 (the case #3854 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.

#3854 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 #3822): 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 #3822 stays with triggered02. This PR is the fix only.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5612878193 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3883). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-02T19:03:02Z. --- Fixes #3822 (the case #3854 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`. #3854 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 #3822): 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 #3822 stays with triggered02. This PR is the fix only. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
R0Y00 commented 2026-12-02 19:19:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:19:45Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157304777 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3883#pullrequestreview-6157304777). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:19:45Z. **Review:** APPROVED --- 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.
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
R0Y00/Xbox2Windows!3883
No description provided.