Skip to content

Commit

Permalink
ssh remoting: Kill SSH master process when dropping client (zed-indus…
Browse files Browse the repository at this point in the history
…tries#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 <bennet@zed.dev>
  • Loading branch information
mrnugget and bennetbo authored Sep 25, 2024
1 parent a6cb17f commit 300bf87
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/remote/src/ssh_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct SshSession {

struct SshClientState {
socket: SshSocket,
_master_process: process::Child,
master_process: process::Child,
_temp_dir: TempDir,
}

Expand Down Expand Up @@ -593,7 +593,7 @@ impl SshClientState {
connection_options,
socket_path,
},
_master_process: master_process,
master_process,
_temp_dir: temp_dir,
})
}
Expand Down Expand Up @@ -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<S: AsRef<OsStr>>(&self, program: S) -> process::Command {
let mut command = process::Command::new("ssh");
Expand Down

0 comments on commit 300bf87

Please sign in to comment.