Skip to content

Commit

Permalink
Reset keepalive-timer after sending keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
amtelekom authored and mmirate committed Dec 6, 2023
1 parent 7b9a3f0 commit f5b4670
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ impl Session {
#[allow(clippy::panic)] // false positive in select! macro
while !self.common.disconnected {
self.common.received_data = false;
let mut only_sent_keepalive = false;
let mut sent_keepalive = false;
tokio::select! {
r = &mut reading => {
let (stream_read, buffer, mut opening_cipher) = match r {
Expand Down Expand Up @@ -827,13 +827,13 @@ impl Session {
reading.set(start_reading(stream_read, buffer, opening_cipher));
}
() = &mut keepalive_timer => {
self.send_keepalive(true);
only_sent_keepalive = true;
if self.common.config.keepalive_max != 0 && self.common.alive_timeouts > self.common.config.keepalive_max {
debug!("Timeout, server not responding to keepalives");
break
}
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
self.send_keepalive(true);
sent_keepalive = true;
}
() = &mut inactivity_timer => {
debug!("timeout");
Expand Down Expand Up @@ -892,15 +892,15 @@ impl Session {
}
}

if self.common.received_data {
if self.common.received_data || sent_keepalive {
if let (futures::future::Either::Right(ref mut sleep), Some(d)) = (
keepalive_timer.as_mut().as_pin_mut(),
self.common.config.keepalive_interval,
) {
sleep.as_mut().reset(tokio::time::Instant::now() + d);
}
}
if !only_sent_keepalive {
if !sent_keepalive {
if let (futures::future::Either::Right(ref mut sleep), Some(d)) = (
inactivity_timer.as_mut().as_pin_mut(),
self.common.config.inactivity_timeout,
Expand Down
10 changes: 5 additions & 5 deletions russh/src/server/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl Session {
#[allow(clippy::panic)] // false positive in macro
while !self.common.disconnected {
self.common.received_data = false;
let mut only_sent_keepalive = false;
let mut sent_keepalive = false;
tokio::select! {
r = &mut reading => {
let (stream_read, buffer, mut opening_cipher) = match r {
Expand Down Expand Up @@ -416,13 +416,13 @@ impl Session {
reading.set(start_reading(stream_read, buffer, opening_cipher));
}
() = &mut keepalive_timer => {
only_sent_keepalive = true;
self.keepalive_request();
if self.common.config.keepalive_max != 0 && self.common.alive_timeouts > self.common.config.keepalive_max {
debug!("Timeout, server not responding to keepalives");
break
}
self.common.alive_timeouts = self.common.alive_timeouts.saturating_add(1);
sent_keepalive = true;
self.keepalive_request();
}
() = &mut inactivity_timer => {
debug!("timeout");
Expand Down Expand Up @@ -500,15 +500,15 @@ impl Session {
.map_err(crate::Error::from)?;
self.common.write_buffer.buffer.clear();

if self.common.received_data {
if self.common.received_data || sent_keepalive {
if let (futures::future::Either::Right(ref mut sleep), Some(d)) = (
keepalive_timer.as_mut().as_pin_mut(),
self.common.config.keepalive_interval,
) {
sleep.as_mut().reset(tokio::time::Instant::now() + d);
}
}
if !only_sent_keepalive {
if !sent_keepalive {
if let (futures::future::Either::Right(ref mut sleep), Some(d)) = (
inactivity_timer.as_mut().as_pin_mut(),
self.common.config.inactivity_timeout,
Expand Down

0 comments on commit f5b4670

Please sign in to comment.