Skip to content

Commit 5c3ac6e

Browse files
authored
Fix off-by-one error for keepalive timer (#543)
1 parent f18b7f2 commit 5c3ac6e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

russh/src/client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,13 @@ impl Session {
11151115
reading.set(start_reading(stream_read, buffer, opening_cipher));
11161116
}
11171117
() = &mut keepalive_timer => {
1118+
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
11181119
if self.common.config.keepalive_max != 0 && self.common.alive_timeouts > self.common.config.keepalive_max {
11191120
debug!("Timeout, server not responding to keepalives");
11201121
return Err(crate::Error::KeepaliveTimeout.into());
11211122
}
1122-
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
1123-
self.send_keepalive(true)?;
11241123
sent_keepalive = true;
1124+
self.send_keepalive(true)?;
11251125
}
11261126
() = &mut inactivity_timer => {
11271127
debug!("timeout");

russh/src/server/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,11 @@ impl Session {
543543
reading.set(start_reading(stream_read, buffer, opening_cipher));
544544
}
545545
() = &mut keepalive_timer => {
546+
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
546547
if self.common.config.keepalive_max != 0 && self.common.alive_timeouts > self.common.config.keepalive_max {
547548
debug!("Timeout, client not responding to keepalives");
548549
return Err(crate::Error::KeepaliveTimeout.into());
549550
}
550-
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
551551
sent_keepalive = true;
552552
self.keepalive_request()?;
553553
}

0 commit comments

Comments
 (0)