From bb87cbdd28618ce510f83f58678c2f4592cb89b2 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Tue, 6 Apr 2021 11:09:13 +0200 Subject: [PATCH] fix(terminal): do not hang app if terminal refuses to quit (#255) --- src/common/command_is_executing.rs | 4 ++-- src/common/os_input_output.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/command_is_executing.rs b/src/common/command_is_executing.rs index 93c44eb6..775a7bfc 100644 --- a/src/common/command_is_executing.rs +++ b/src/common/command_is_executing.rs @@ -23,7 +23,7 @@ impl CommandIsExecuting { let (lock, cvar) = &*self.closing_pane; let mut closing_pane = lock.lock().unwrap(); *closing_pane = false; - cvar.notify_one(); + cvar.notify_all(); } pub fn opening_new_pane(&mut self) { let (lock, _cvar) = &*self.opening_new_pane; @@ -34,7 +34,7 @@ impl CommandIsExecuting { let (lock, cvar) = &*self.opening_new_pane; let mut opening_new_pane = lock.lock().unwrap(); *opening_new_pane = false; - cvar.notify_one(); + cvar.notify_all(); } pub fn wait_until_pane_is_closed(&self) { let (lock, cvar) = &*self.closing_pane; diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index de0c6a3b..013b9f12 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -242,7 +242,13 @@ impl OsApi for OsInputOutput { Box::new(stdout) } fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error> { - kill(Pid::from_raw(pid), Some(Signal::SIGINT)).unwrap(); + // TODO: + // Ideally, we should be using SIGINT rather than SIGKILL here, but there are cases in which + // the terminal we're trying to kill hangs on SIGINT and so all the app gets stuck + // that's why we're sending SIGKILL here + // A better solution would be to send SIGINT here and not wait for it, and then have + // a background thread do the waitpid stuff and send SIGKILL if the process is stuck + kill(Pid::from_raw(pid), Some(Signal::SIGKILL)).unwrap(); waitpid(Pid::from_raw(pid), None).unwrap(); Ok(()) }