mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-03 14:01:30 +01:00
remote_server: Use CreateProcess to spawn daemon on Windows (#55292)
When connecting to a Windows host over SSH, the proxy fails to start the daemon and the user sees "failed to spawn server." **Root cause** `spawn_server_windows` invokes the daemon via `shell_execute_from_explorer`, which goes through COM `ShellWindows` / `IShellDispatch2::ShellExecute`. That path requires both: - `explorer.exe` running in the caller's session, and - an interactive desktop / window station. Neither is available when `zed-remote-server proxy` is launched by sshd: sshd-spawned processes live in a non-interactive window station with no Explorer. The COM call fails, the `run` daemon never starts, the proxy's 10s socket-existence poll times out, and the connection fails. A commenter on #48966 reports the connection succeeds after first logging in via RDP, which is consistent with this diagnosis: RDP login populates the session with `explorer.exe` and an interactive window station. **Fix** Replace the COM path with a direct `Command::spawn`, matching the non-Windows branch. Use `DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP` creation flags so the daemon has no inherited console and is not killed by Ctrl+C/Break broadcast to the parent's group when the proxy exits. Bypass `util::new_command` because it presets `CREATE_NO_WINDOW`, which Win32 disallows combining with `DETACHED_PROCESS`. Drop one layer to `smol::process::Command` directly to keep the disallowed-methods lint happy. Also drop the now-unused `shell_execute_from_explorer` module and the `windows` crate dependency it pulled in. No automated test is included: exercising this path requires a headless OpenSSH-Server-on-Windows host with a non-interactive window station, which CI doesn't currently provide. Verified manually that macOS client -> Windows host over SSH establishes the connection successfully where it previously timed out. Closes #48966 Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed remote server failing to start when connecting to a Windows host over SSH --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: John Tur <john-tur@outlook.com>
This commit is contained in:
4 files changed
+22
-71
No files matched your search
Generated
-1
@@ -15043,7 +15043,6 @@ dependencies = [
|
||||
"util",
|
||||
"uuid",
|
||||
"watch",
|
||||
"windows 0.62.2",
|
||||
"workspace",
|
||||
"worktree",
|
||||
"zlog",
|
||||
|
||||
@@ -79,7 +79,6 @@ uuid = { workspace = true, features = ["v4"] }
|
||||
libc.workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows.workspace = true
|
||||
gpui = { workspace = true, features = ["windows-manifest"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -3,9 +3,6 @@ mod headless_project;
|
||||
#[cfg(test)]
|
||||
mod remote_editing_tests;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub mod windows;
|
||||
|
||||
pub use headless_project::{HeadlessAppState, HeadlessProject};
|
||||
|
||||
use anyhow::{Context as _, Result, anyhow};
|
||||
@@ -1191,24 +1188,28 @@ async fn spawn_server(paths: &ServerPaths) -> Result<(), SpawnServerError> {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn spawn_server_windows(binary_name: &Path, paths: &ServerPaths) -> Result<(), SpawnServerError> {
|
||||
let binary_path = binary_name.to_string_lossy().to_string();
|
||||
let parameters = format!(
|
||||
"run --log-file \"{}\" --pid-file \"{}\" --stdin-socket \"{}\" --stdout-socket \"{}\" --stderr-socket \"{}\"",
|
||||
paths.log_file.to_string_lossy(),
|
||||
paths.pid_file.to_string_lossy(),
|
||||
paths.stdin_socket.to_string_lossy(),
|
||||
paths.stdout_socket.to_string_lossy(),
|
||||
paths.stderr_socket.to_string_lossy()
|
||||
);
|
||||
|
||||
let directory = binary_name
|
||||
.parent()
|
||||
.map(|p| p.to_string_lossy().to_string())
|
||||
.unwrap_or_default();
|
||||
|
||||
crate::windows::shell_execute_from_explorer(&binary_path, ¶meters, &directory)
|
||||
.map_err(|e| SpawnServerError::ProcessStatus(std::io::Error::other(e)))?;
|
||||
|
||||
use smol::process::windows::CommandExt;
|
||||
// Detach from the console and break away from sshd's job so closing the SSH session doesn't kill the daemon.
|
||||
const DETACHED_PROCESS: u32 = 0x0000_0008;
|
||||
const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x0100_0000;
|
||||
smol::process::Command::new(binary_name)
|
||||
.stdin(util::command::Stdio::null())
|
||||
.stdout(util::command::Stdio::null())
|
||||
.stderr(util::command::Stdio::null())
|
||||
.arg("run")
|
||||
.arg("--log-file")
|
||||
.arg(&paths.log_file)
|
||||
.arg("--pid-file")
|
||||
.arg(&paths.pid_file)
|
||||
.arg("--stdin-socket")
|
||||
.arg(&paths.stdin_socket)
|
||||
.arg("--stdout-socket")
|
||||
.arg(&paths.stdout_socket)
|
||||
.arg("--stderr-socket")
|
||||
.arg(&paths.stderr_socket)
|
||||
.creation_flags(DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB)
|
||||
.spawn()
|
||||
.map_err(SpawnServerError::ProcessStatus)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
use windows::Win32::System::Com::{
|
||||
CLSCTX_LOCAL_SERVER, COINIT_APARTMENTTHREADED, CoCreateInstance, CoInitializeEx, IDispatch,
|
||||
IServiceProvider,
|
||||
};
|
||||
use windows::Win32::System::Variant::VARIANT;
|
||||
use windows::Win32::UI::Shell::{
|
||||
CSIDL_DESKTOP, IShellBrowser, IShellDispatch2, IShellFolderViewDual, IShellWindows,
|
||||
SID_STopLevelBrowser, SVGIO_BACKGROUND, SWC_DESKTOP, SWFO_NEEDDISPATCH, ShellWindows,
|
||||
};
|
||||
use windows::core::{BSTR, Interface};
|
||||
|
||||
pub fn shell_execute_from_explorer(
|
||||
file: &str,
|
||||
parameters: &str,
|
||||
directory: &str,
|
||||
) -> anyhow::Result<()> {
|
||||
unsafe {
|
||||
CoInitializeEx(None, COINIT_APARTMENTTHREADED).unwrap();
|
||||
|
||||
let mut _hwnd = Default::default();
|
||||
let shell_dispatch: IShellDispatch2 =
|
||||
CoCreateInstance::<_, IShellWindows>(&ShellWindows, None, CLSCTX_LOCAL_SERVER)?
|
||||
.FindWindowSW(
|
||||
&VARIANT::from(CSIDL_DESKTOP as i32),
|
||||
&VARIANT::default(),
|
||||
SWC_DESKTOP,
|
||||
&mut _hwnd,
|
||||
SWFO_NEEDDISPATCH,
|
||||
)?
|
||||
.cast::<IServiceProvider>()?
|
||||
.QueryService::<IShellBrowser>(&SID_STopLevelBrowser)?
|
||||
.QueryActiveShellView()?
|
||||
.GetItemObject::<IDispatch>(SVGIO_BACKGROUND)?
|
||||
.cast::<IShellFolderViewDual>()?
|
||||
.Application()?
|
||||
.cast()?;
|
||||
|
||||
shell_dispatch.ShellExecute(
|
||||
&BSTR::from(file),
|
||||
&VARIANT::from(parameters),
|
||||
&VARIANT::from(directory),
|
||||
&VARIANT::from(""),
|
||||
&VARIANT::from(0i32),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user