From bc4abd2b29d1424d157fc267ea99f2f5a754fcf2 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 9 Oct 2024 19:40:09 +0200 Subject: [PATCH] ssh session: Fix hang when doing state update in reconnect (#18934) This snuck in last-minute. Release Notes: - Fixed a potential hang and panic when an SSH project goes through a slow reconnect. --- crates/remote/src/ssh_session.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index d79c3eb8d0..e709fd726e 100644 --- a/crates/remote/src/ssh_session.rs +++ b/crates/remote/src/ssh_session.rs @@ -563,6 +563,7 @@ impl SshRemoteClient { return Ok(()); } drop(lock); + self.set_state(State::Reconnecting, cx); log::info!("Trying to reconnect to ssh server... Attempt {}", attempts); @@ -734,6 +735,7 @@ impl SshRemoteClient { } else { state.heartbeat_recovered() }; + self.set_state(next_state, cx); if missed_heartbeats >= MAX_MISSED_HEARTBEATS { @@ -877,8 +879,12 @@ impl SshRemoteClient { cx: &mut ModelContext, map: impl FnOnce(&State) -> Option, ) { - if let Some(new_state) = self.state.lock().as_ref().and_then(map) { - self.set_state(new_state, cx); + let mut lock = self.state.lock(); + let new_state = lock.as_ref().and_then(map); + + if let Some(new_state) = new_state { + lock.replace(new_state); + cx.notify(); } }