From 4d598eb1ad3998abfa56cacaa59a644f17263bb7 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 11 Oct 2022 07:55:39 -0700 Subject: [PATCH] mux: fix stale local/remote window id mapping in mux client When closing the all mux tabs in a window, the remote will close the window. If the local has a mixture of local and remote tabs then subsequent attempts to spawn a tab in that window would fail due to reusing the stale remote window id. This commit purges the local/remote mappings that are (probably) dead when the remote indicates that a pane has been removed. The mapping should be re-established as needed later on. refs: https://github.com/wez/wezterm/issues/2614 --- docs/changelog.md | 3 ++ wezterm-client/src/domain.rs | 45 +++++++++++++++++++++++++++ wezterm-client/src/pane/clientpane.rs | 2 ++ 3 files changed, 50 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 5175ceab4..77157bafc 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,6 +78,9 @@ As features stabilize some brief notes about them will accumulate here. [#2559](https://github.com/wez/wezterm/issues/2559) * Missing validation of conflicting domain names [#2618](https://github.com/wez/wezterm/issues/2618) +* Creating tabs in a multiplexing domain could fail after previously closing + all tabs connected to that domain in that window + [#2614](https://github.com/wez/wezterm/issues/2614) #### Changed * Removed Last Resort fallback font diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs index 490689b3b..a383cadee 100644 --- a/wezterm-client/src/domain.rs +++ b/wezterm-client/src/domain.rs @@ -37,6 +37,51 @@ impl ClientInner { map.get(&remote_window_id).cloned() } + pub(crate) fn expire_stale_mappings(&self) { + let mux = Mux::get().unwrap(); + + self.remote_to_local_pane + .lock() + .unwrap() + .retain(|_remote_pane_id, local_pane_id| mux.get_pane(*local_pane_id).is_some()); + + self.remote_to_local_tab + .lock() + .unwrap() + .retain( + |_remote_tab_id, local_tab_id| match mux.get_tab(*local_tab_id) { + Some(tab) => { + for pos in tab.iter_panes_ignoring_zoom() { + if pos.pane.domain_id() == self.local_domain_id { + return true; + } + } + false + } + None => false, + }, + ); + + self.remote_to_local_window + .lock() + .unwrap() + .retain( + |_remote_window_id, local_window_id| match mux.get_window(*local_window_id) { + Some(w) => { + for tab in w.iter() { + for pos in tab.iter_panes_ignoring_zoom() { + if pos.pane.domain_id() == self.local_domain_id { + return true; + } + } + } + false + } + None => false, + }, + ); + } + fn record_remote_to_local_window_mapping( &self, remote_window_id: WindowId, diff --git a/wezterm-client/src/pane/clientpane.rs b/wezterm-client/src/pane/clientpane.rs index ccd876d44..7e0b49e26 100644 --- a/wezterm-client/src/pane/clientpane.rs +++ b/wezterm-client/src/pane/clientpane.rs @@ -168,6 +168,8 @@ impl ClientPane { self.renderable.borrow().inner.borrow_mut().dead = true; let mux = Mux::get().unwrap(); mux.prune_dead_windows(); + + self.client.expire_stale_mappings(); } _ => bail!("unhandled unilateral pdu: {:?}", pdu), };