Closed vkill closed 1 year ago
I have replaced it with Semaphore.
I will merge if it solves the problem.
Sorry, it seems like this was not the issue after all :(
After testing against multiple branches and SSH config settings, I found out that the issue is not in fact related to MaxStartups
, but MaxSessions
instead.
Increasing MaxSessions
fixed the issue I was having, even on the main
branch.
However, this does not make any sense to me. Does your bb8-async-ssh2-lite crate multiplex all its sessions over a single TCP connection? I was under the impression it opened a new one each time.
According to a few Google searches MaxSessions
only applies to the number of sessions on a single TCP connection.
I was under the impression it opened a new one each time
No, please read bb8 README.
I was under the impression it opened a new one each time
No, please read bb8 README.
Sorry, let me rephrase. I meant that every time bb8 wants a new session, it also opens a new TCP connection. https://github.com/bk-rs/ssh-rs/blob/44a3332092ff70c99ed55fe9db6194c37056afe1/bb8-async-ssh2-lite/src/impl_tokio.rs#L142 As opposed to every new session being on the same TCP stream.
every time bb8 wants a new session, it also opens a new TCP connection.
Yes, So we should use max_size
to limit the max TCP conns.
every time bb8 wants a new session, it also opens a new TCP connection.
Yes, So we should use
max_size
to limit the max TCP conns.
Theoretically yes, but the documentation for MaxSessions
says this:
MaxSessions Specifies the maximum number of open shell, login or subsystem (e.g. sftp) sessions permitted per network connection. Multiple sessions may be established by clients that support connection multiplexing. Setting MaxSessions to 1 will effectively disable session multiplexing, whereas setting it to 0 will prevent all shell, login and subsystem sessions while still permitting for- warding. The default is 10.
It explicitly says that it limits the number of sessions per connection, but we are only ever using one session per connection? If I understand it correctly, changing that setting should have absolutely no effect on my program. Yet increasing it eliminates the errors I have. I will see what happens if I limit the number of connections in bb8 directly. If that fixes my issue, then there's either a very cursed bug or sshd's docs are weird.
So, it has nothing to do with bb8. But can set max_lifetime
Anyway, this PR can still solve some MaxStartups problems.
And the MaxSessions is 10. And log has 'no more sessions'.
So, I still suggest https://github.com/bk-rs/ssh-rs/issues/28#issuecomment-1396405173 , enable tokio rt-multi-thread
feature, don't care MaxSessions, set max_number_of_unauthenticated_conns is MaxStartups
The example
You're effectively reimplementing https://docs.rs/tokio/latest/tokio/sync/struct.Semaphore.html Using a Semaphore would also have the advantage that you could just
.await
a permit instead of sleeping for an arbitrary amount of time. I believe that havingAsyncSessionManagerWithTokioTcpStream
own a Semaphore and acquiring a permit for the duration of an unauthenticated connection would be a cleaner way to solve this :thinking: