fix(libkernel): treat a raise target that is already terminating as exited on Windows #12069
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12069"
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 boykopovar/AnyPS5. Originally posted by dantdmdarealguy on 2026-10-27T18:38:16Z.
What
guest_raise_exceptionfails intermittently on Windows CI on currentmain. Every failure aborts at the same place,Exception.cpp:700:It failed in 9 of the 193 Windows jobs of
build.ymlruns onmainon 2026-10-27, including two runs on2ee8e9751a(jobs 122272870002 and 122272290778). It failed in none of the 114 Windows jobs on 2026-10-26. The jobs that passed ran the same commits as the failing ones.Since #10666 (
1b9c5feb30), a raise whose target is in host code is handed to a background deliverer. The deliverer sweeps the target withTryDeliveruntil the handler is taken or the thread exits. Each sweep starts withSuspendThread. When that fails,TryDeliveronly counts the target as gone if its handle is already signaled; otherwise it throws, and the deliverer aborts the process.A thread that has begun to exit sits in a window where
SuspendThreadalready fails withERROR_ACCESS_DENIED(NtSuspendThreadreturnsSTATUS_THREAD_IS_TERMINATING,0xC000004B), but its handle is not signaled yet andGetExitCodeThreadstill returnsSTILL_ACTIVE. A standalone probe on Windows 11 measured this: 20,000 threads, each suspended in a loop while it returned. 9,977SuspendThreadfailures (allGetLastError5) and 9,973NtSuspendThreadfailures (all0xC000004B) came before the handle was signaled. Every handle was signaled shortly afterwards.guest_raise_exceptionhits the window when a thread it raised at exits while the deliverer still has that raise in its sweep list. For example, the handler was delivered at the thread's return breakpoint, and the test stopped and joined the thread before the next sweep retired the raise.TryDelivernow suspends throughNtSuspendThread. It takesSTATUS_THREAD_IS_TERMINATINGasAttempt::Exited, which is what it already did for a signaled handle: the deliverer drops the raise, and a directsceKernelRaiseExceptionreturnsESRCH. Any other suspend failure still throws.DisarmReturnBreakalready tolerated a failed suspend and is unchanged.guest_raise_exiting_thread(new, Windows) reproduces the abort directly. In each of 100 rounds it starts 32 guest threads that block in a hostWaitForSingleObject, raises SIGUSR1 at each (so every raise goes to the deliverer), then releases them all and joins them. Every raise must return 0 and the process must not abort. It takes about 0.4 s.Closed #1802 (October 9) handled the same Windows behaviour in the code from before the deliverer, as part of a larger change. It was closed because no title hit the race and its branch merged other pull requests. The race now fails
main's Windows CI, through a path #10666 added.This is separate from #11813 and #12005. #11813 is the
address waking round N: the handler did not run within 5 sabort of the same test, and #12005 speeds up delivery to busy host-code targets. Neither touches the suspend failure. This change neither depends on #12005 nor overlaps its lines.Tested
Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON,SDL_AUDIODRIVER=dummy, onmain2ee8e9751a.CI evidence on
main, Windows job ofbuild.yml:cannot suspend the target threadThe 2026-10-27 failures were jobs 122146244109, 122146653804, 122170202472, 122201223723, 122219271843, 122272290778, 122272870002, 122294206442 and 122320201238.
guest_raise_exiting_thread, the same test executable run 100 times with eachlibkernel.prx:main: 100/100 aborted, all in the deliverer (libkernel.prx+0x12ce05). 93 printedcannot suspend the target thread; the other 7 lost that line to interleaved output.ctest -R '^guest_raise_exiting_thread$' --repeat until-fail:100passed alone (33.8 s) and as two concurrent loops (100/100 each).guest_raise_exception, four concurrent loops of 10 runs each:main1/40, this change 0/40. The onemainfailure was #11813'saddress wakingtimeout. The CI suspend abort didn't occur locally in these 40 runs, nor in 9 full-suite runs onmain.guest_raise_exiting_threadis the deterministic reproduction.ctest --output-on-failure --timeout 120 --parallel 2 -R "^guest_raise|^guest_cond_timedwait$|patched_libraries"with this change: 16/17 passed, andpatched_librariesprinted368 patched libraries loaded, 0 failed. The failure wasguest_raise_exceptionwithaddress waking round 28: the handler did not run within 5 s, which is #11813 and not this change. The test passed in all 40 loop runs above.cmake --buildand--target libspass with no warnings in the touched files.check_test_registration.py:1470 test executable(s), 0 built and not run as recorded, none new.check_conventions.py --base origin/main: passed.pr_overlap.py: no overlap. Four open PRs that changeException.cppcouldn't be compared because they conflict withmain(#4630, #5021, #7192, #8592); none of them changes the suspend lines. The commit merges cleanly ontomain14332cd8d0.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T19:04:09Z.
Review: APPROVED
The status handling is consistent with NTSTATUS semantics:
STATUS_THREAD_IS_TERMINATINGis classified as an exited target, while other failed suspends still require a signaled handle or remain errors. The Windows stress test raises at 32 blocked guest threads over 100 release rounds; the reported 100/100 baseline aborts and 0/100 changed runs directly exercise the race, with additional repeated/concurrent runs reported. I checked the exact-head diff, current-main merge preview,check_conventions.py, andgit diff --check.The hosted Windows job is green but did not run this test: its changed-test selection,
libsbuild, and CTest steps were skipped. This approval relies on the detailed Windows 11 build and repeated test results recorded by the author; I could not independently execute this Windows-only test in the Linux environment.