Loader: handle thread spawn failure in detach_all without panicking #1994
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1996"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Androtim on 2026-11-25T02:35:04Z.
Root cause
detach_all()(registered viaatexit) callsstd::thread::spawnfor the 5-second detach watchdog. During WindowsExitProcessteardown,CreateThreadcan fail withERROR_ACCESS_DENIED(OS error 5), causingstd::thread::spawnto panic insideatexit(unhandled exception 0x20474343incrashes.log) instead of finishingDLL_PROCESS_DETACH.Fix
std::thread::Builder::new().spawn(...)incrates/victory-loader/src/threads.rsinstead of panicking onspawn.Ok, keep the existing watchdog TID wait loop and pass&[watchdog]toend_other_threads.Err, skip the 5-second watchdog wait loop and pass&[]toend_other_threadssoDLL_PROCESS_DETACHruns immediately without stalling or panicking.threads::tests::exit_process_runs_detach_all_without_panic(viaexit_process_childcallingattached(0)+ExitProcess(0)) to verifydetach_allcompletes cleanly underExitProcess.Verification
cargo clippy --workspace --all-targets --locked -- -D warnings(passed)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(passed)cargo test -p victory-loader --lib --locked(36 passed, 0 failed)cargo test -p xtask --locked(6 passed, 0 failed)Imported from Marvisak/VIctory. Originally posted by DesertGamer on 2026-11-25T02:40:47Z.
VIctory V2: community PRs, merged and tested
Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.
Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).
⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.
Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2
Unofficial community fork of Marvisak/VIctory, GPL-3.0.
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T02:59:22Z.
Triage verdict — Needs a regression test (
267fc01)Evidence
detach_all. At267fc01,attached(0)registers the callback with the CRT, thenexit_process_childcalls Win32ExitProcess(0)and the parent checks only exit status.Checks and limits
extern "C" atexitregistration, both exit paths returned 0. The callback marker appeared with CRTexit(0)and was absent withExitProcess(0). This was a synthetic runtime probe, not a rerun of the loader suite. CRT termination docsNext step
This verification was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:32:47Z.
Review: APPROVED
Verified locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b—cargo check -p victory-loader --lockedpasses clean (2 pre-existing warnings).Thread-spawn failure in
detach_allno longer panics — correct error propagation for a destructor-ish path that must not unwind. Note: victory-loader's test suite is broken on macOS/Linux on main pre-existing (prepare::tests parse Mach-O as PE), so runtime verification is Windows-only; the compile check + small diff is the evidence here. Approving.Imported from Marvisak/VIctory. Originally posted by Androtim on 2026-11-25T07:00:35Z.
Thanks for the catch @jeremygold02! Pushed commit
f129d1faddressing all three points:ExitProcess(0)test with two deterministic subprocess tests:atexit_runs_detach_all(atexit_child): registers a prior LIFOatexitcallback and exits via CRTstd::process::exit(0), asserting thatdetach_allran (EXITING == true).detach_all_handles_watchdog_spawn_failure(detach_spawn_failure_child): injectsPermissionDeniedintodetach_all_withto exercise the watchdog spawn-error branch directly, verifying no panic,EXITING == true, and that other threads terminate.start_detach_watchdog: when spawning fails during teardown, detach proceeds without a watchdog deadline rather than panicking across theextern "C"atexitboundary.Verified locally on Windows 11 (
x86_64-pc-windows-gnu):cargo test -p victory-loader --lib --locked: 38 passed, 0 failedcargo test -p xtask --locked: 6 passed, 0 failedcargo clippy --workspace --all-targets --locked -- -D warningsand--all-features: cleanImported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:19:10Z.
Automated triage for the maintainers.
Merge candidate.
crates/victory-loader/src/threads.rs,detach_all: the watchdog is now started withstd::thread::Builder::spawn(moved intostart_detach_watchdog), so a failedCreateThreadduring teardown no longer panics inside theextern "C"atexitcallback (which aborts the process). On failure, detach runs without the 5 s deadline andend_other_threadskeeps no thread. The success path is unchanged from main. I checked that the movedWATCHDOGwait loop is identical, that the test helpersbusy/stoppedmatch main's signatures, and that the new tests cover both the CRTexitpath (atexit_child, which asserts thatdetach_allactually ran, as an earlier review asked) and an injected spawn failure (detach_spawn_failure_child). No other open PR makes this change on its own; #1304 and #1456 touch the same file only as part of much larger rewrites.Trade-off for the maintainer: if spawning fails, a detach that hangs is no longer bounded by the watchdog. The PR documents this, and it replaces an abort that happened every time.
CI: passing (
check).Recommending a look, not approving.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:04:51Z.
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because the failure needs a toolchain the project does not build with.
CreateThreadis refused only when the atexit table runs afterExitProcesshas begun, which is how the windows-gnu CRT behaves (the crash code cited, 0x20474343, is libgcc's). The repo pins x86_64-pc-windows-msvc, where the atexit table runs beforeExitProcess, so theErrbranch is unreachable there and the change would trade the watchdog's bounded exit for an unbounded one. If gnu builds are to be supported, three lines would do:Builder::spawnand anif let Okaround the wait.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Imported from Marvisak/VIctory. Originally posted by jaschinski97-ops on 2026-11-26T15:47:49Z.
Independent native Windows11 control now supports the toolchain distinction in the closing comment.
I built identical source
08b4585(main63bcca43 plus the two Windows path/save fixes, without #1996) with Rust1.98.1 GNU and MSVC. The same tiny title returns 0,1,31,0x12345678,0x80000001 and0xFFFFFFFF. On GNU, all5 nonzero statuses become0xC0000409 after a teardown panic. On MSVC, all6 statuses are preserved and there is no panic on the same PC. Its four directory-change/DLL/storage controls pass too.Source, exact matrix, commands and artifact SHA-256. MSVC build/test run passed19 app,156 HLE and35 loader tests before building the release executable. The earlier separate GNU experiment with original #1996 also passes, with its original author/history retained; this is verification evidence, not a new production PR.
AI-assisted with Codex; own synthetic programs only, no GPU/game data. No failure reproduced on the supported MSVC build.
Pull request closed