From 94df22a1c09fbfcf722bf2a6d29b35b2cb3b2354 Mon Sep 17 00:00:00 2001 From: Brad Heller Date: Tue, 12 Aug 2025 16:20:17 +0100 Subject: [PATCH] chore: Local apps should terminate themselves when dropped --- crates/tower-runtime/src/local.rs | 7 +++++++ crates/tower-uv/src/lib.rs | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/crates/tower-runtime/src/local.rs b/crates/tower-runtime/src/local.rs index 56977443..a9da7dfb 100644 --- a/crates/tower-runtime/src/local.rs +++ b/crates/tower-runtime/src/local.rs @@ -269,6 +269,13 @@ async fn execute_local_app(opts: StartOptions, sx: oneshot::Sender, cancel_ return Ok(()) } +impl Drop for LocalApp { + fn drop(&mut self) { + // We want to ensure that we cancel the process if it is still running. + let _ = self.terminate(); + } +} + impl App for LocalApp { async fn start(opts: StartOptions) -> Result { let cancel_token = CancellationToken::new(); diff --git a/crates/tower-uv/src/lib.rs b/crates/tower-uv/src/lib.rs index c25d02e5..878faecd 100644 --- a/crates/tower-uv/src/lib.rs +++ b/crates/tower-uv/src/lib.rs @@ -78,6 +78,7 @@ impl Uv { debug!("Executing UV ({:?}) venv in {:?}", &self.uv_path, cwd); let child = Command::new(&self.uv_path) + .kill_on_drop(true) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -95,6 +96,7 @@ impl Uv { if cwd.join("pyproject.toml").exists() { debug!("Executing UV ({:?}) sync in {:?}", &self.uv_path, cwd); let child = Command::new(&self.uv_path) + .kill_on_drop(true) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -112,6 +114,7 @@ impl Uv { // If there is a requirements.txt, then we can use that to sync. let child = Command::new(&self.uv_path) + .kill_on_drop(true) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -138,6 +141,7 @@ impl Uv { debug!("Executing UV ({:?}) run {:?} in {:?}", &self.uv_path, program, cwd); let child = Command::new(&self.uv_path) + .kill_on_drop(true) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped())