From 300bf87f77d3ae4eea93affc088b7f6b4979a277 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 25 Sep 2024 12:45:53 +0200 Subject: [PATCH] ssh remoting: Kill SSH master process when dropping client (#18331) This was a process leak. Since we use `.spawn()`, the process continued to run in the background, even if our `SshClientState` was dropped. Means we need to manually clean it up. Release Notes: - N/A Co-authored-by: Bennet --- crates/remote/src/ssh_session.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index 9d9d916f19b45..06a7f810e6721 100644 --- a/crates/remote/src/ssh_session.rs +++ b/crates/remote/src/ssh_session.rs @@ -56,7 +56,7 @@ pub struct SshSession { struct SshClientState { socket: SshSocket, - _master_process: process::Child, + master_process: process::Child, _temp_dir: TempDir, } @@ -593,7 +593,7 @@ impl SshClientState { connection_options, socket_path, }, - _master_process: master_process, + master_process, _temp_dir: temp_dir, }) } @@ -716,6 +716,14 @@ impl SshClientState { } } +impl Drop for SshClientState { + fn drop(&mut self) { + if let Err(error) = self.master_process.kill() { + log::error!("failed to kill SSH master process: {}", error); + } + } +} + impl SshSocket { fn ssh_command>(&self, program: S) -> process::Command { let mut command = process::Command::new("ssh");