fixed missing CHANNEL_CLOSE messages - #459

This commit is contained in:
Eugene Pankov 2022-11-20 13:59:29 +01:00
parent a29b2b6079
commit d90abcfb50
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4
4 changed files with 22 additions and 12 deletions

4
Cargo.lock generated
View file

@ -3199,9 +3199,9 @@ dependencies = [
[[package]]
name = "russh"
version = "0.35.0-beta.5"
version = "0.35.0-beta.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "355d7ad01489febf7f475495a898b49987f4fa79b2a70bfee3e109194a5ed93b"
checksum = "0c130a5e8cb48fd94d117612590cd029924e3d968403c4064c709795fac0d52f"
dependencies = [
"aes",
"aes-gcm",

View file

@ -12,8 +12,8 @@ bimap = "0.6"
bytes = "1.2"
dialoguer = "0.10"
futures = "0.3"
russh = { version = "0.35.0-beta.5", features = ["vendored-openssl"] }
# russh = { version = "0.35.0-beta.5", features = ["vendored-openssl"], path = "../../russh/russh"}
russh = { version = "0.35.0-beta.6", features = ["vendored-openssl"] }
# russh = { version = "0.35.0-beta.6", features = ["vendored-openssl"], path = "../../russh/russh"}
russh-keys = { version = "0.23.0-beta.1", features = ["vendored-openssl"] }
# russh-keys = { version = "0.23.0-beta.1", features = ["vendored-openssl"], path = "../../russh/russh-keys" }
sea-orm = { version = "0.10.3", features = [

View file

@ -16,6 +16,7 @@ pub struct SessionChannel {
ops_rx: UnboundedReceiver<ChannelOperation>,
events_tx: UnboundedSender<RCEvent>,
session_id: SessionId,
closed: bool,
}
impl SessionChannel {
@ -32,6 +33,7 @@ impl SessionChannel {
ops_rx,
events_tx,
session_id,
closed: false,
}
}
@ -110,7 +112,6 @@ impl SessionChannel {
)).map_err(|_| SshClientError::MpscError)?;
}
Some(russh::ChannelMsg::Close) => {
self.events_tx.send(RCEvent::Close(self.channel_id)).map_err(|_| SshClientError::MpscError)?;
break;
},
Some(russh::ChannelMsg::Success) => {
@ -147,19 +148,31 @@ impl SessionChannel {
warn!("unhandled channel message: {:?}", msg);
}
None => {
self.events_tx.send(RCEvent::Close(self.channel_id)).map_err(|_| SshClientError::MpscError)?;
break
},
}
}
}
}
self.close()?;
Ok(())
}
fn close(&mut self) -> Result<(), SshClientError> {
if !self.closed {
let _ = self
.events_tx
.send(RCEvent::Close(self.channel_id))
.map_err(|_| SshClientError::MpscError);
self.closed = true;
}
Ok(())
}
}
impl Drop for SessionChannel {
fn drop(&mut self) {
let _ = self.close();
info!(channel=%self.channel_id, session=%self.session_id, "Closed");
}
}

View file

@ -241,15 +241,12 @@ impl RemoteClient {
op => {
let mut channel_pipes = self.channel_pipes.lock().await;
match channel_pipes.get(&channel_id) {
Some(tx) => match tx.send(op) {
Ok(_) => {}
Err(SendError(_)) => {
Some(tx) => {
if tx.send(op).is_err() {
channel_pipes.remove(&channel_id);
}
},
None => {
debug!(channel=%channel_id, "operation for unknown channel")
}
None => debug!(channel=%channel_id, "operation for unknown channel"),
}
}
}