Skip to content

Commit

Permalink
added specific error types for keepalive and inactivity timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Feb 26, 2024
1 parent 5c60d30 commit 45edb29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,15 +818,15 @@ impl Session {
() = &mut keepalive_timer => {
if self.common.config.keepalive_max != 0 && self.common.alive_timeouts > self.common.config.keepalive_max {
debug!("Timeout, server not responding to keepalives");
break
return Err(crate::Error::KeepaliveTimeout);
}
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
self.send_keepalive(true);
sent_keepalive = true;
}
() = &mut inactivity_timer => {
debug!("timeout");
break
return Err(crate::Error::InactivityTimeout);
}
msg = self.receiver.recv(), if !self.is_rekeying() => {
match msg {
Expand Down
8 changes: 8 additions & 0 deletions russh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ pub enum Error {
#[error("Connection timeout")]
ConnectionTimeout,

/// Keepalive timeout.
#[error("Keepalive timeout")]
KeepaliveTimeout,

/// Inactivity timeout.
#[error("Inactivity timeout")]
InactivityTimeout,

/// Missing authentication method.
#[error("No authentication method")]
NoAuthMethod,
Expand Down
4 changes: 2 additions & 2 deletions russh/src/server/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ impl Session {
() = &mut keepalive_timer => {
if self.common.config.keepalive_max != 0 && self.common.alive_timeouts > self.common.config.keepalive_max {
debug!("Timeout, client not responding to keepalives");
break
return Err(crate::Error::KeepaliveTimeout);
}
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
sent_keepalive = true;
self.keepalive_request();
}
() = &mut inactivity_timer => {
debug!("timeout");
break
return Err(crate::Error::InactivityTimeout);
}
msg = self.receiver.recv(), if !self.is_rekeying() => {
match msg {
Expand Down

0 comments on commit 45edb29

Please sign in to comment.