Skip to content

Commit cd59590

Browse files
amtelekomEugeny
authored andcommitted
Enforce client timeout
1 parent 3463ed0 commit cd59590

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

russh/src/client/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ use crate::key::PubKey;
103103
use crate::session::{CommonSession, EncryptedState, Exchange, Kex, KexDhDone, KexInit, NewKeys};
104104
use crate::ssh_read::SshRead;
105105
use crate::sshbuffer::{SSHBuffer, SshId};
106-
use crate::{auth, msg, negotiation, ChannelId, ChannelOpenFailure, Disconnect, Limits, Sig};
106+
use crate::{
107+
auth, msg, negotiation, timeout, ChannelId, ChannelOpenFailure, Disconnect, Limits, Sig,
108+
};
107109

108110
mod encrypted;
109111
mod kex;
@@ -772,6 +774,8 @@ impl Session {
772774
pin!(reading);
773775
pin!(time_for_keepalive);
774776

777+
let delay = self.common.config.inactivity_timeout;
778+
775779
#[allow(clippy::panic)] // false positive in select! macro
776780
while !self.common.disconnected {
777781
tokio::select! {
@@ -852,6 +856,10 @@ impl Session {
852856
}
853857
}
854858
}
859+
_ = timeout(delay) => {
860+
debug!("timeout");
861+
break
862+
},
855863
}
856864
self.flush()?;
857865
if !self.common.write_buffer.buffer.is_empty() {

russh/src/server/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,6 @@ thread_local! {
650650
static B2: RefCell<CryptoVec> = RefCell::new(CryptoVec::new());
651651
}
652652

653-
pub(crate) async fn timeout(delay: Option<std::time::Duration>) {
654-
if let Some(delay) = delay {
655-
tokio::time::sleep(delay).await
656-
} else {
657-
futures::future::pending().await
658-
};
659-
}
660-
661653
async fn start_reading<R: AsyncRead + Unpin>(
662654
mut stream_read: R,
663655
mut buffer: SSHBuffer,

0 commit comments

Comments
 (0)