From fd89ea0423bccce0df5a38f8956bfe0aac88c3f7 Mon Sep 17 00:00:00 2001 From: kernel-sanders <1490292+kernel-sanders@users.noreply.github.com> Date: Wed, 28 Jun 2023 19:13:34 -0400 Subject: [PATCH 1/2] fix: spawn code_serer with CREATE_NO_WINDOW fixes #184058 --- cli/src/tunnels/code_server.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/src/tunnels/code_server.rs b/cli/src/tunnels/code_server.rs index 1246e1c9441..fe257a64314 100644 --- a/cli/src/tunnels/code_server.rs +++ b/cli/src/tunnels/code_server.rs @@ -541,6 +541,15 @@ impl<'a> ServerBuilder<'a> { debug!(self.logger, "Starting server with command... {:?}", cmd); + // On Windows spawning a code-server binary will run cmd.exe /c C:\path\to\code-server.cmd... + // This spawns a cmd.exe window for the user, which if they close will kill the code-server process + // and disconnect the tunnel. To prevent this, pass the CREATE_NO_WINDOW flag to the Command + // only on Windows. + // Original issue: https://github.com/microsoft/vscode/issues/184058 + // Partial fix: https://github.com/microsoft/vscode/pull/184621 + #[cfg(target_os = "windows")] + let cmd = cmd.creation_flags(0x08000000); // 0x08000000 == CREATE_NO_WINDOW see https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags + let child = cmd .stderr(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) From 4c469c5f8e600d8174a31697ef89c33685898a9c Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Thu, 3 Aug 2023 10:57:02 -0700 Subject: [PATCH 2/2] use winapi constant instead --- cli/src/tunnels/code_server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/tunnels/code_server.rs b/cli/src/tunnels/code_server.rs index 8ff9e640d13..5bc5e39514a 100644 --- a/cli/src/tunnels/code_server.rs +++ b/cli/src/tunnels/code_server.rs @@ -548,8 +548,8 @@ impl<'a> ServerBuilder<'a> { // Original issue: https://github.com/microsoft/vscode/issues/184058 // Partial fix: https://github.com/microsoft/vscode/pull/184621 #[cfg(target_os = "windows")] - let cmd = cmd.creation_flags(0x08000000); // 0x08000000 == CREATE_NO_WINDOW see https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags - + let cmd = cmd.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW); + let child = cmd .stderr(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped())