Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix MCP server processes leaking as zombies (#54793)
Richard Feldman29aad02404ae
diff --git a/Cargo.lock b/Cargo.lockindex 48e486af705..6133cdf67e8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3571,7 +3571,6 @@ version = "0.1.0"dependencies = ["anyhow","async-channel 2.5.0",- "async-process","async-trait","base64 0.22.1","collections",diff --git a/crates/context_server/Cargo.toml b/crates/context_server/Cargo.tomlindex 3a51accb780..39288c5a6d8 100644--- a/crates/context_server/Cargo.toml+++ b/crates/context_server/Cargo.toml@@ -17,7 +17,6 @@ test-support = ["gpui/test-support"][dependencies]anyhow.workspace = trueasync-channel.workspace = true-async-process.workspace = trueasync-trait.workspace = truebase64.workspace = truecollections.workspace = truediff --git a/crates/context_server/src/transport/stdio_transport.rs b/crates/context_server/src/transport/stdio_transport.rsindex 4bf4b77cda7..5ee5fc30c22 100644--- a/crates/context_server/src/transport/stdio_transport.rs+++ b/crates/context_server/src/transport/stdio_transport.rs@@ -1,15 +1,16 @@use std::path::PathBuf;use std::pin::Pin;-use anyhow::{Context as _, Result};-use async_process::Child;+use anyhow::Result;use async_trait::async_trait;use futures::io::{BufReader, BufWriter};use futures::{AsyncBufReadExt as _, AsyncRead, AsyncWrite, AsyncWriteExt as _, Stream, StreamExt as _,};use gpui::AsyncApp;+use util::TryFutureExt as _;+use util::process::Child;use util::shell::Shell;use util::shell_builder::ShellBuilder;@@ -31,22 +32,20 @@ impl StdioTransport {) -> Result<Self> {let builder = ShellBuilder::new(&Shell::System, cfg!(windows)).non_interactive();let mut command =- builder.build_smol_command(Some(binary.executable.display().to_string()), &binary.args);+ builder.build_std_command(Some(binary.executable.display().to_string()), &binary.args);- command- .envs(binary.env.unwrap_or_default())- .stdin(std::process::Stdio::piped())- .stdout(std::process::Stdio::piped())- .stderr(std::process::Stdio::piped())- .kill_on_drop(true);+ command.envs(binary.env.unwrap_or_default());if let Some(working_directory) = working_directory {command.current_dir(working_directory);}- let mut server = command- .spawn()- .with_context(|| format!("failed to spawn command {command:?})",))?;+ let mut server = Child::spawn(+ command,+ std::process::Stdio::piped(),+ std::process::Stdio::piped(),+ std::process::Stdio::piped(),+ )?;let stdin = server.stdin.take().unwrap();let stdout = server.stdout.take().unwrap();diff --git a/crates/project/src/context_server_store.rs b/crates/project/src/context_server_store.rsindex 1ea6d2c4188..9effe4a4638 100644--- a/crates/project/src/context_server_store.rs+++ b/crates/project/src/context_server_store.rs@@ -607,10 +607,7 @@ impl ContextServerStore {let server = state.server();let configuration = state.configuration();- let mut result = Ok(());- if let ContextServerState::Running { server, .. } = &state {- result = server.stop();- }+ let result = server.stop();drop(state);self.update_server_state(