Skip to content

Commit

Permalink
Close Channels on Disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
amtelekom authored and Eugeny committed Nov 10, 2023
1 parent cd59590 commit 43bdc07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,10 @@ impl Session {
}
}
debug!("disconnected");
if self.common.disconnected {
stream_write.shutdown().await.map_err(crate::Error::from)?;
}
self.receiver.close();
self.inbound_channel_receiver.close();
stream_write.shutdown().await.map_err(crate::Error::from)?;

Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions russh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,11 @@ impl ChannelParams {
self.confirmed = true;
}
}

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
};
}
4 changes: 2 additions & 2 deletions russh/src/server/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Session {
// Either this packet is a KEXINIT, in which case we start a key re-exchange.

#[allow(clippy::unwrap_used)]
let mut enc = self.common.encrypted.as_mut().unwrap();
let enc = self.common.encrypted.as_mut().unwrap();
if buf.first() == Some(&msg::KEXINIT) {
debug!("Received rekeying request");
// If we're not currently rekeying, but `buf` is a rekey request
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Session {
};

#[allow(clippy::unwrap_used)]
let mut enc = self.common.encrypted.as_mut().unwrap();
let enc = self.common.encrypted.as_mut().unwrap();
// If we've successfully read a packet.
match enc.state {
EncryptedState::WaitingAuthServiceRequest {
Expand Down

0 comments on commit 43bdc07

Please sign in to comment.