Skip to content

Commit

Permalink
ssh remoting: Emit Disconnected when reconnected exhausted (zed-indus…
Browse files Browse the repository at this point in the history
…tries#19540)

Release Notes:

- N/A

---------

Co-authored-by: Bennet <[email protected]>
  • Loading branch information
mrnugget and bennetbo authored Oct 22, 2024
1 parent 4f52077 commit 27d1a56
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions crates/remote/src/ssh_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ impl State {
matches!(self, Self::ReconnectExhausted { .. })
}

fn is_server_not_running(&self) -> bool {
matches!(self, Self::ServerNotRunning)
}

fn is_reconnecting(&self) -> bool {
matches!(self, Self::Reconnecting { .. })
}
Expand Down Expand Up @@ -700,7 +704,6 @@ impl SshRemoteClient {
if this.state_is(State::is_reconnect_failed) {
this.reconnect(cx)
} else if this.state_is(State::is_reconnect_exhausted) {
cx.emit(SshRemoteEvent::Disconnected);
Ok(())
} else {
log::debug!("State has transition from Reconnecting into new state while attempting reconnect.");
Expand Down Expand Up @@ -870,6 +873,9 @@ impl SshRemoteClient {
let len = child_stderr
.read(&mut stderr_buffer[stderr_offset..])
.await?;
if len == 0 {
return Err(anyhow!("stderr is closed"));
}

stderr_offset += len;
let mut start_ix = 0;
Expand Down Expand Up @@ -929,7 +935,6 @@ impl SshRemoteClient {
log::error!("failed to reconnect because server is not running");
this.update(&mut cx, |this, cx| {
this.set_state(State::ServerNotRunning, cx);
cx.emit(SshRemoteEvent::Disconnected);
})?;
}
}
Expand Down Expand Up @@ -972,7 +977,14 @@ impl SshRemoteClient {

fn set_state(&self, state: State, cx: &mut ModelContext<Self>) {
log::info!("setting state to '{}'", &state);

let is_reconnect_exhausted = state.is_reconnect_exhausted();
let is_server_not_running = state.is_server_not_running();
self.state.lock().replace(state);

if is_reconnect_exhausted || is_server_not_running {
cx.emit(SshRemoteEvent::Disconnected);
}
cx.notify();
}

Expand Down

0 comments on commit 27d1a56

Please sign in to comment.