russh
russh copied to clipboard
Memory ballooning with forwarding
Summary
Sending data over a remote forward causes memory to balloon by the amount of data sent through the tunnel. This does not appear to happen when sending data over, say, the default channel.
Minimum reproducible example
Making to small changes to the echoserver.rs
example demonstrates the issue:
async fn data(
mut self,
channel: ChannelId,
data: &[u8],
mut session: Session,
) -> Result<(Self, Session), Self::Error> {
///// Remove the other code here to eliminate confounding factors.
Ok((self, session))
}
async fn tcpip_forward(
self,
address: &str,
port: &mut u32,
session: Session,
) -> Result<(Self, bool, Session), Self::Error> {
let handle = session.handle();
let address = address.to_string();
let port = *port;
tokio::spawn(async move {
let mut channel = handle
.channel_open_forwarded_tcpip(address, port, "1.2.3.4", 1234)
.await
.unwrap();
let _ = channel.data(&b"Hello from a forwarded port"[..]).await;
///// Instead of sending an EOF, sleep forever
tokio::time::sleep(std::time::Duration::from_secs(u64::MAX)).await;
});
Ok((self, true, session))
}
Then, after starting the echo server,
# In the background, listen on port 1234 and send an infinite string of 0s to whatever client connects.
socat TCP-LISTEN:1234,reuseaddr SYSTEM:'yes 0' &
# Forward traffic to localhost port 1234; ignore server SSH keys. Connect to localhost port 2222.
ssh -R 2048:localhost:1234 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 localhost
This causes memory usage to continue to balloon.
However, there is no memory ballooning when sending to the tty.
cat /dev/zero | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 localhost
Expected behaviour
I would expect that the amount of memory consumed is roughly proportional to the channel's transfer rate (faster rate = more data buffered), not the total amount of data sent through the channel.