bk-rs / ssh-rs

https://docs.rs/async-ssh2-lite
Apache License 2.0
56 stars 21 forks source link

Add an option to limit the number of concurrent handshakes in bb8-async-ssh2-lite #32

Closed netthier closed 1 year ago

netthier commented 1 year ago

By default, the sshd server limits the maximum amount of open, unauthenticated sessions (MaxStartups). If many new SSH connections are opened simultaneously via bb8, that limit can be reached and will result in connection failures. As far as I know, there is no such limit for authenticated sessions. By limiting the amount of concurrent connect calls (e.g. via a Semaphore), this issue should be solveable.

vkill commented 1 year ago

bb8 can configure via https://docs.rs/bb8/0.8.0/bb8/struct.Builder.html#method.max_size . e.g. let pool = bb8::Pool::builder().max_size(10).build(mgr).await?;

netthier commented 1 year ago

That's the limit on all active connections though. The issue is that servers like sshd only limit the number of maximum unauthenticated connections: https://stackoverflow.com/a/63174013 Because authentication doesn't happen in exactly the same moment as connection, the limit of unauthenticated connections can be reached by just opening multiple sessions at once. I want to be able to have theoretically infinite authenticated sessions, but limit the amount of currently handshaking ones.

vkill commented 1 year ago

Oh, I see. I will think about it.

vkill commented 1 year ago

So, do you mean this?

vkill commented 1 year ago

@netthier We can continue discuss https://github.com/bk-rs/ssh-rs/pull/34 in here.