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.
This commit is contained in:
Thorsten Ball 2024-10-09 19:40:09 +02:00 committed by GitHub
parent 71f4ca67c2
commit bc4abd2b29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<Self>,
map: impl FnOnce(&State) -> Option<State>,
) {
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();
}
}