diff --git a/cli/src/tunnels/code_server.rs b/cli/src/tunnels/code_server.rs index 16cc3325a4a8e..c9821446049d8 100644 --- a/cli/src/tunnels/code_server.rs +++ b/cli/src/tunnels/code_server.rs @@ -479,7 +479,7 @@ impl<'a> ServerBuilder<'a> { .arg("--enable-remote-auto-shutdown") .arg(format!("--port={}", port)); - let child = self.spawn_server_process(cmd)?; + let child = self.spawn_server_process(cmd).await?; let log_file = self.get_logfile()?; let plog = self.logger.prefixed(&log::new_code_server_prefix()); @@ -553,7 +553,7 @@ impl<'a> ServerBuilder<'a> { .arg("--enable-remote-auto-shutdown") .arg(format!("--socket-path={}", socket.display())); - let child = self.spawn_server_process(cmd)?; + let child = self.spawn_server_process(cmd).await?; let log_file = self.get_logfile()?; let plog = self.logger.prefixed(&log::new_code_server_prefix()); @@ -594,13 +594,13 @@ impl<'a> ServerBuilder<'a> { let mut cmd = self.get_base_command(); cmd.args(args); - let child = self.spawn_server_process(cmd)?; + let child = self.spawn_server_process(cmd).await?; let plog = self.logger.prefixed(&log::new_code_server_prefix()); Ok(monitor_server::(child, None, plog, true)) } - fn spawn_server_process(&self, mut cmd: Command) -> Result { + async fn spawn_server_process(&self, mut cmd: Command) -> Result { info!(self.logger, "Starting server..."); debug!(self.logger, "Starting server with command... {:?}", cmd); @@ -615,7 +615,10 @@ impl<'a> ServerBuilder<'a> { let cmd = cmd.creation_flags( winapi::um::winbase::CREATE_NO_WINDOW | winapi::um::winbase::CREATE_NEW_PROCESS_GROUP - | winapi::um::winbase::CREATE_BREAKAWAY_FROM_JOB, + | get_should_use_breakaway_from_job() + .await + .then_some(winapi::um::winbase::CREATE_BREAKAWAY_FROM_JOB) + .unwrap_or_default(), ); let child = cmd @@ -874,3 +877,13 @@ pub async fn download_cli_into_cache( } } } + +#[cfg(target_os = "windows")] +async fn get_should_use_breakaway_from_job() -> bool { + let mut cmd = Command::new("cmd"); + cmd.creation_flags( + winapi::um::winbase::CREATE_NO_WINDOW | winapi::um::winbase::CREATE_BREAKAWAY_FROM_JOB, + ); + + cmd.args(["/C", "echo ok"]).output().await.is_ok() +}