Repository navigation
fix(windows): end the session without spawning new processes - #6127
Merged
Merged
Conversation
During Windows logoff or shutdown, new processes fail to initialize, so the shutdown path must not launch any (issue #6054). The hidden window now lets WM_QUERYENDSESSION through and only acts on WM_ENDSESSION(TRUE); a console handler maps Ctrl+C/Break to a normal exit and close, logoff and shutdown events to a session end. A session end stores Kill in the core's stop strategy so the core is not stopped through the Ctrl+C helper, skips any recorded restart, and waits at most 30 seconds for cleanup. Service commands, including the status probe, refuse to spawn while SM_SHUTTINGDOWN is set, so recovery cannot start the service mid-shutdown. Fixes #6054
Changed Files
|
greenhat616
approved these changes
Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6054. Replaces the closed #6117/#6119/#6122 with a smaller, one-way design that follows the maintainer review on libnyanpasu/nyanpasu-utils#218.
Depends on (both merged): libnyanpasu/nyanpasu-utils#219 (
StopStrategy, defaultGraceful) and libnyanpasu/nyanpasu-runtime#475 (CoreManagerBuilder::stop_strategy). The runtime gitlink moves toa27c3fc; the service binary is unchanged, so no runtime release is needed.Changes
backend/tauri/src/shutdown_hook.rs):WM_QUERYENDSESSIONreturns TRUE and does nothing;WM_ENDSESSION(FALSE)is logged only;WM_ENDSESSION(TRUE)logs the LOGOFF/CRITICAL/CLOSEAPP flags, sends a session end once, and waits for cleanup at most 30 s with a shutdown block reason. The unusedCleaningUpstate is removed. No new statics.SetConsoleCtrlHandlermaps Ctrl+C/Break to a normal graceful exit and CLOSE/LOGOFF/SHUTDOWN to a session end, sharing the same trigger and bounded wait. Debug builds run in a console and previously died on Ctrl+C without cleanup.setup.rsshares oneArc<AtomicStopStrategy>with the local core (local_host::build) and the hook. A session end storesKillbefore requesting exit, so the core is not stopped through thenyanpasu-service --nyanpasu-process-shutdownhelper. Normal exits stay graceful.nyanpasu-core/src/service/control.rs): on Windows,statusand elevated service commands returnServiceCommandError::SessionEndingwithout spawning whileGetSystemMetrics(SM_SHUTTINGDOWN)is set. The service actor classifies it asUnknown, so recovery cannot launch an elevated start if the service stops on PRESHUTDOWN before the app receivesWM_ENDSESSION.Out of scope (follow-ups): revocation on
WM_ENDSESSION(FALSE), the in-process SCM/IPC status probe (P3), and service-side PRESHUTDOWN timing (P5).Tests
Message → action and console event → trigger mappings, one-shot session end across window and console,
Killstored before exit and normal stop staying graceful,ExitGatesuppressing restart, and service-actor recovery publishingUnknownwith zero daemon starts.Verified on Linux:
cargo test -p clash-nyanpasu,cargo test -p nyanpasu-core(except the WSL-onlytest_device_model_not_empty), clippy, fmt,lint:architecture-ledger,lint:backend-boundaries, typecheck.Needs Windows verification
nyanpasu-service.exe,sc.exe, UAC or relauncher after the session ends; hook returns within 30 s.