fix(tauri): force Windows process tree shutdown (#240)
## Summary - force the Windows CLI process tree shutdown path during normal app close - avoid leaving child server processes alive when the direct wrapper process exits first - keep the change limited to the Windows shutdown path in cli_manager ## Testing - cargo check --manifest-path packages/tauri-app/src-tauri/Cargo.toml
This commit is contained in:
@@ -51,6 +51,8 @@ fn workspace_root() -> Option<PathBuf> {
|
|||||||
const SESSION_COOKIE_NAME: &str = "codenomad_session";
|
const SESSION_COOKIE_NAME: &str = "codenomad_session";
|
||||||
|
|
||||||
const CLI_STOP_GRACE_SECS: u64 = 30;
|
const CLI_STOP_GRACE_SECS: u64 = 30;
|
||||||
|
#[cfg(windows)]
|
||||||
|
const CLI_WINDOWS_FORCE_GRACE_MS: u64 = 2_000;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn configure_posix_process_group(command: &mut Command) {
|
fn configure_posix_process_group(command: &mut Command) {
|
||||||
@@ -402,6 +404,8 @@ impl CliProcessManager {
|
|||||||
let mut child_opt = self.child.lock();
|
let mut child_opt = self.child.lock();
|
||||||
if let Some(mut child) = child_opt.take() {
|
if let Some(mut child) = child_opt.take() {
|
||||||
log_line(&format!("stopping CLI pid={}", child.id()));
|
log_line(&format!("stopping CLI pid={}", child.id()));
|
||||||
|
#[cfg(windows)]
|
||||||
|
let mut forced_tree_shutdown = false;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
unsafe {
|
unsafe {
|
||||||
let pid = child.id() as i32;
|
let pid = child.id() as i32;
|
||||||
@@ -414,9 +418,7 @@ impl CliProcessManager {
|
|||||||
}
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
if !kill_process_tree_windows(child.id(), false) {
|
let _ = kill_process_tree_windows(child.id(), false);
|
||||||
let _ = child.kill();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
@@ -424,6 +426,21 @@ impl CliProcessManager {
|
|||||||
match child.try_wait() {
|
match child.try_wait() {
|
||||||
Ok(Some(_)) => break,
|
Ok(Some(_)) => break,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
|
#[cfg(windows)]
|
||||||
|
if !forced_tree_shutdown
|
||||||
|
&& start.elapsed() > Duration::from_millis(CLI_WINDOWS_FORCE_GRACE_MS)
|
||||||
|
{
|
||||||
|
log_line(&format!(
|
||||||
|
"regular Windows shutdown still running after {}ms; escalating pid={}",
|
||||||
|
CLI_WINDOWS_FORCE_GRACE_MS,
|
||||||
|
child.id()
|
||||||
|
));
|
||||||
|
forced_tree_shutdown = true;
|
||||||
|
if !kill_process_tree_windows(child.id(), true) {
|
||||||
|
let _ = child.kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if start.elapsed() > Duration::from_secs(CLI_STOP_GRACE_SECS) {
|
if start.elapsed() > Duration::from_secs(CLI_STOP_GRACE_SECS) {
|
||||||
log_line(&format!(
|
log_line(&format!(
|
||||||
"stop timed out after {}s; sending SIGKILL pid={}",
|
"stop timed out after {}s; sending SIGKILL pid={}",
|
||||||
@@ -440,7 +457,11 @@ impl CliProcessManager {
|
|||||||
}
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
if !kill_process_tree_windows(child.id(), true) {
|
if !forced_tree_shutdown
|
||||||
|
&& !kill_process_tree_windows(child.id(), true)
|
||||||
|
{
|
||||||
|
let _ = child.kill();
|
||||||
|
} else if forced_tree_shutdown {
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user