Skip to content

Commit

Permalink
Enforce client timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
amtelekom authored and Eugeny committed Nov 10, 2023
1 parent 3463ed0 commit cd59590
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 9 additions & 1 deletion russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ use crate::key::PubKey;
use crate::session::{CommonSession, EncryptedState, Exchange, Kex, KexDhDone, KexInit, NewKeys};
use crate::ssh_read::SshRead;
use crate::sshbuffer::{SSHBuffer, SshId};
use crate::{auth, msg, negotiation, ChannelId, ChannelOpenFailure, Disconnect, Limits, Sig};
use crate::{
auth, msg, negotiation, timeout, ChannelId, ChannelOpenFailure, Disconnect, Limits, Sig,
};

mod encrypted;
mod kex;
Expand Down Expand Up @@ -772,6 +774,8 @@ impl Session {
pin!(reading);
pin!(time_for_keepalive);

let delay = self.common.config.inactivity_timeout;

#[allow(clippy::panic)] // false positive in select! macro
while !self.common.disconnected {
tokio::select! {
Expand Down Expand Up @@ -852,6 +856,10 @@ impl Session {
}
}
}
_ = timeout(delay) => {
debug!("timeout");
break
},
}
self.flush()?;
if !self.common.write_buffer.buffer.is_empty() {
Expand Down
8 changes: 0 additions & 8 deletions russh/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,6 @@ thread_local! {
static B2: RefCell<CryptoVec> = RefCell::new(CryptoVec::new());
}

pub(crate) async fn timeout(delay: Option<std::time::Duration>) {
if let Some(delay) = delay {
tokio::time::sleep(delay).await
} else {
futures::future::pending().await
};
}

async fn start_reading<R: AsyncRead + Unpin>(
mut stream_read: R,
mut buffer: SSHBuffer,
Expand Down

0 comments on commit cd59590

Please sign in to comment.