Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

Stop reconnecting on a codec version mismatch and say so visibly

RoversX1c48113854a2
diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs
index 667c0769..7cd6ace3 100644
--- a/wezterm-client/src/client.rs
+++ b/wezterm-client/src/client.rs
@@ -32,7 +32,7 @@ use std::os::windows::io::{AsRawSocket, AsSocket, BorrowedSocket, RawSocket};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, AtomicU8, Ordering};
use std::sync::mpsc::channel;
-use std::sync::{Arc, RwLock};
+use std::sync::{Arc, Mutex, RwLock};
use std::thread;
use std::time::Duration;
use thiserror::Error;
@@ -188,6 +188,13 @@ pub struct Client {
/// reconnect gets a fresh value so queued unilateral messages from the
/// superseded reader cannot be mistaken for current server state.
connection_generation: Arc<AtomicU64>,
+ /// Set when a reconnect cycle hits an error that retrying can never fix
+ /// (a codec version mismatch). The transport reconnects fine in that
+ /// state, so without this the loop would cycle "Reconnecting..."
+ /// forever, showing the real error only to a headless UI. The reconnect
+ /// loop checks it after every dead session, surfaces it in a visible
+ /// window, and stops.
+ fatal_connection_error: Arc<Mutex<Option<String>>>,
}
impl Client {
@@ -1510,6 +1517,8 @@ impl Client {
let remote_server_id = Arc::new(RwLock::new(None));
let connection_generation = Arc::new(AtomicU64::new(0));
let reader_connection_generation = Arc::clone(&connection_generation);
+ let fatal_connection_error = Arc::new(Mutex::new(None));
+ let reader_fatal_connection_error = Arc::clone(&fatal_connection_error);
thread::spawn(move || {
const BASE_INTERVAL: Duration = Duration::from_secs(1);
@@ -1611,6 +1620,19 @@ impl Client {
break;
}
+ // A fatal error reported by the reattach task (codec
+ // version mismatch). The transport itself reconnects
+ // fine, so retrying would cycle forever with the real
+ // error visible only to a headless UI; show it in a
+ // window of its own and stop.
+ if let Some(reason) = reader_fatal_connection_error.lock().unwrap().take() {
+ log::error!("{reason}; won't try to reconnect");
+ let ui = ConnectionUI::new_with_no_close_delay();
+ ui.title("ThinkTerm: connection failed");
+ ui.output_str(&format!("{reason}\n"));
+ break;
+ }
+
reader_connection_phase
.store(ClientConnectionPhase::Reconnecting as u8, Ordering::Release);
crate::domain::wake_thinkterm_frontend();
@@ -1842,9 +1864,20 @@ impl Client {
resume_reconnect_tx,
remote_server_id,
connection_generation,
+ fatal_connection_error,
}
}
+ /// Mark the connection as failed in a way no amount of retrying can fix.
+ /// The reconnect loop surfaces the reason and stops after the current
+ /// session dies.
+ pub fn set_fatal_connection_error(&self, reason: String) {
+ self.fatal_connection_error
+ .lock()
+ .unwrap()
+ .replace(reason);
+ }
+
pub fn into_client_domain_config(self) -> ClientDomainConfig {
self.client_domain_config
}
diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs
index 3cc44c5b..dd9b9469 100644
--- a/wezterm-client/src/domain.rs
+++ b/wezterm-client/src/domain.rs
@@ -1684,7 +1684,22 @@ impl ClientDomain {
.ok_or_else(|| anyhow!("domain {domain_id} disappeared during reattach"))?;
ui.output_str("Checking server version and restoring client identity\n");
- let server = inner.client.verify_version_compat(&ui).await?;
+ let server = match inner.client.verify_version_compat(&ui).await {
+ Ok(server) => server,
+ Err(err) => {
+ // A version mismatch cannot be fixed by reconnecting: the
+ // transport comes up fine every time and this check fails
+ // every time. Tell the reconnect loop to surface it and
+ // stop, instead of cycling "Reconnecting..." forever.
+ if err
+ .downcast_ref::<crate::client::IncompatibleVersionError>()
+ .is_some()
+ {
+ inner.client.set_fatal_connection_error(format!("{err:#}"));
+ }
+ return Err(err);
+ }
+ };
let server_replaced =
server_runtime_replaced(prior_server_id.as_deref(), &server.server_id);
if inner.client.connection_generation() != connection_generation {