diff --git a/russh/src/client/mod.rs b/russh/src/client/mod.rs index d83df836..1b5d580f 100644 --- a/russh/src/client/mod.rs +++ b/russh/src/client/mod.rs @@ -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 { @@ -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"); @@ -892,7 +892,7 @@ 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, @@ -900,7 +900,7 @@ impl Session { 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, diff --git a/russh/src/server/session.rs b/russh/src/server/session.rs index 69ab59d9..1707ddef 100644 --- a/russh/src/server/session.rs +++ b/russh/src/server/session.rs @@ -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 { @@ -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"); @@ -500,7 +500,7 @@ 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, @@ -508,7 +508,7 @@ impl Session { 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,