mux: try harder to re-attach to tabs on reconnect

If we'd decided to close a tab due to an error bubbling up in the
reader, we need to re-assign a local id when we enumerate tabs.

This is a bit of a crutch: ideally we'd not close the tab and
instead show some kind of UI to indicate that it is not responding.

refs: https://github.com/wez/wezterm/issues/127
This commit is contained in:
Wez Furlong committed 2020-02-22 07:29:27 -08:00
1 parent 1ac0358cb8
commit 097092b36d
1 file changed
+21 -8
+21 -8
View File
@@ -56,6 +56,11 @@ impl ClientInner {
None
}
pub fn remove_old_tab_mapping(&self, remote_tab_id: TabId) {
let mut tab_map = self.remote_to_local_tab.lock().unwrap();
tab_map.remove(&remote_tab_id);
}
pub fn remote_to_local_tab_id(&self, remote_tab_id: TabId) -> Option<TabId> {
let mut tab_map = self.remote_to_local_tab.lock().unwrap();
@@ -190,14 +195,22 @@ impl ClientDomain {
let tab;
if let Some(tab_id) = inner.remote_to_local_tab_id(entry.tab_id) {
tab = mux.get_tab(tab_id).ok_or_else(|| {
anyhow!(
"remote tab {} should map to local tab {} but \
that tab isn't present in the muxer",
entry.tab_id,
tab_id
)
})?;
match mux.get_tab(tab_id) {
Some(t) => tab = t,
None => {
// We likely decided that we hit EOF on the tab and
// removed it from the mux. Let's add it back, but
// with a new id.
inner.remove_old_tab_mapping(entry.tab_id);
tab = Rc::new(ClientTab::new(
&inner,
entry.tab_id,
entry.size,
&entry.title,
));
mux.add_tab(&tab)?;
}
};
} else {
log::info!(
"attaching to remote tab {} in remote window {} {}",