From 5e6ce47330ba9b7d95cd84fefa0ab061b3d12e2e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 25 Jul 2022 21:05:41 -0700 Subject: [PATCH] fix "no pane" tab hang when two panes close at once There was a race condition where we could leave the tab active index pointing to the wrong pane. That meant that the tab information computed by the gui layer would see no panes marked as active, and thus would end up with no active tab. This commit fixes that by clamping the active index to the number of panes. refs: https://github.com/wez/wezterm/issues/2304 --- docs/changelog.md | 1 + mux/src/tab.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index e8f3986fb..15597ca7f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -73,6 +73,7 @@ As features stabilize some brief notes about them will accumulate here. * [gui-startup](config/lua/gui-events/gui-startup.md) now passes a [SpawnCommand](config/lua/SpawnCommand.md) parameter representing the `wezterm start` command arguments. * Tab `x` button is no longer obscured by tab title text for long tab titles [#2269](https://github.com/wez/wezterm/issues/2269) * Cursor position could end up in the wrong place when rewrapping lines and the cursor was on the rewrap boundary [#2162](https://github.com/wez/wezterm/issues/2162) +* Two or more panes closing at the same time could result in their containing tab hanging and being stuck with "no pane" for a title [#2304](https://github.com/wez/wezterm/issues/2304) #### Updated * Bundled harfbuzz to 4.4.1 diff --git a/mux/src/tab.rs b/mux/src/tab.rs index 528b9d8bd..710325e82 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -1406,7 +1406,13 @@ impl Tab { } } } - *self.active.borrow_mut() = active_idx; + // Even though we try to adjust active_idx for a removed pane, + // we may end up with a value that is out of range in the case + // where two panes close in the span of the same call. + // We account for that and fix things up by clamping the + // active index to pane_index (which after the loop above + // now is the count of panes in this tab). + *self.active.borrow_mut() = active_idx.min(pane_index.saturating_sub(1)); } if !dead_panes.is_empty() && kill {