From d62d2a51339f3cdc6f8ef37a083498f6aa0c94fd Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 20 Mar 2021 12:16:56 -0700 Subject: [PATCH] avoid blocking forever in LocalPane::drop I don't understand how fish ends up blocking forever in the related issue, but it shouldn't block us too! The price of this situation is likely a lingering zombie child process but that seems fine. refs: https://github.com/wez/wezterm/issues/558 --- mux/src/localpane.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index 3bac0448a..26f070205 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -561,12 +561,25 @@ impl LocalPane { } } +fn bounded_kill_wait(child: &mut Box) { + for attempt in 0..5 { + let _ = child.kill(); + if attempt > 0 { + std::thread::sleep(std::time::Duration::from_millis(50)); + } + + if let Ok(Some(_)) = child.try_wait() { + break; + } + } +} + impl Drop for LocalPane { fn drop(&mut self) { - // Avoid lingering zombies + // Avoid lingering zombies if we can, but don't block forever. + // if let ProcessState::Running { child, .. } = &mut *self.process.borrow_mut() { - let _ = child.kill(); - let _ = child.wait(); + bounded_kill_wait(child); } } }