From 39c2da3bdfaa357f0fd120891ea0e757fce19fc7 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 15 Jan 2022 20:02:14 -0700 Subject: [PATCH] avoid race condition when closing last window in a workspace This isn't ideal, but it is better than previously: we would close the window and before the Drop impl had updated the list of known windows, we'd try to re-assign that window to another mux window in a different workspace, but it would never appear because the window was closed. refs: https://github.com/wez/wezterm/issues/1531 --- wezterm-gui/src/frontend.rs | 6 +++--- wezterm-gui/src/termwindow/mod.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 6e9d8e75d..7740eb747 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -178,8 +178,8 @@ impl GuiFrontEnd { self.known_windows.borrow_mut().push(window); } - pub fn forget_known_window(&self, window: Window) { - self.known_windows.borrow_mut().retain(|w| *w != window); + pub fn forget_known_window(&self, window: &Window) { + self.known_windows.borrow_mut().retain(|w| w != window); } } @@ -195,7 +195,7 @@ pub fn record_known_window(window: Window) { }); } -pub fn forget_known_window(window: Window) { +pub fn forget_known_window(window: &Window) { FRONT_END.with(|f| { f.borrow_mut() .as_mut() diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index f5272187d..c405671f6 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -346,6 +346,7 @@ impl TermWindow { // Immediately kill the tabs and allow the window to close mux.kill_window(self.mux_window_id); window.close(); + crate::frontend::forget_known_window(window); } WindowCloseConfirmation::AlwaysPrompt => { let tab = match mux.get_active_tab_for_window(self.mux_window_id) { @@ -353,6 +354,7 @@ impl TermWindow { None => { mux.kill_window(self.mux_window_id); window.close(); + crate::frontend::forget_known_window(window); return; } }; @@ -365,6 +367,7 @@ impl TermWindow { if can_close { mux.kill_window(self.mux_window_id); window.close(); + crate::frontend::forget_known_window(window); return; } let window = self.window.clone().unwrap(); @@ -846,6 +849,7 @@ impl TermWindow { if gl.is_context_lost() { log::error!("opengl context was lost; should reinit"); window.close(); + crate::frontend::forget_known_window(window); return false; } @@ -961,6 +965,7 @@ impl TermWindow { MuxNotification::WindowRemoved(window_id) => { if window_id == self.mux_window_id { window.close(); + crate::frontend::forget_known_window(window); } } _ => {} @@ -995,7 +1000,6 @@ impl TermWindow { } }; self.update_title(); - window.invalidate(); } } @@ -2543,7 +2547,7 @@ impl TermWindow { impl Drop for TermWindow { fn drop(&mut self) { if let Some(window) = self.window.take() { - crate::frontend::forget_known_window(window); + crate::frontend::forget_known_window(&window); } } }