Problem with >10 parallel SSH connections
See original GitHub issueHello there,
I am using AsyncSSH
(which has been absolutely great thus far 🙏 ) in combination with FastAPI
to build a performant, async
-ready API
. Now I have noticed that the opening of multiple parallel connections can cause a few SSH
connections to be dropped, and I was wondering if this was expected behavior given my approach or if I misunderstood something about AsyncSSH
/asyncio
(which I assume to be the case).
My first assumption was that .run
might reuse existing connections and open separate channels (which by default most SSH
-servers only allow 10 of per connection), but from investigating the source code and the access log, it doesn’t look like that. Rather, a separate SSH
-connection is opened for every command - perfect!
I’ve created a minimal reproducible build here. By tweaking the parallel_tasks
variable to >10
I start noticing the issue…
The error I keep seeing is asyncssh.misc.ConnectionLost: Connection lost
, the stacktrace
looks as follows:
Error trying to connect to server via SSH...
Traceback (most recent call last):
File "/home/user/Coding/asyncssh-test/main.py", line 8, in executeCommand
async with asyncssh.connect(
File "/home/user/.local/share/virtualenvs/asyncssh-test-LAQchyfJ/lib/python3.10/site-packages/asyncssh/misc.py", line 274, in __aenter__
self._coro_result = await self._coro
File "/home/user/.local/share/virtualenvs/asyncssh-test-LAQchyfJ/lib/python3.10/site-packages/asyncssh/connection.py", line 7646, in connect
return await asyncio.wait_for(
File "/usr/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
return await fut
File "/home/user/.local/share/virtualenvs/asyncssh-test-LAQchyfJ/lib/python3.10/site-packages/asyncssh/connection.py", line 439, in _connect
await options.waiter
asyncssh.misc.ConnectionLost: Connection lost
Is this an issue with AsyncSSH
or am I simply doing something wrong here?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Happy to help - that sounds like a good approach. If you have any further questions, feel free to ask.
Hi Ronald,
Thanks a million for your feedback and time! This sounds like a really promising approach and I will give it a shot 😃 I think I will start with using semaphores to prevent the
MaxStartups
-issue and later move towards keeping a connection- and session-pool as you suggested.Best, Sean