question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with >10 parallel SSH connections

See original GitHub issue

Hello 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ronfcommented, Feb 25, 2022

Happy to help - that sounds like a good approach. If you have any further questions, feel free to ask.

0reactions
seandlgcommented, Feb 25, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

number of ssh sessions allowed from a server
Specifies the maximum number of open shell, login or subsystem (e.g. sftp) sessions permitted per network connection.
Read more >
Issues · ParallelSSH/parallel-ssh - GitHub
Asynchronous parallel SSH client library. Contribute to ParallelSSH/parallel-ssh development by creating an account on GitHub.
Read more >
Python - Fabric maximum 10 parallel SSH connections
I was hoping the program to open 100 distinct SSH connections and run the Fabric task on all those servers in parallel. However,...
Read more >
Multiple SSH connections to the same system - is it possible?
The short answer - Yes. It usually works by default. The long answer - Depending on what you are using it for, it...
Read more >
How to use parallel ssh (PSSH) for executing commands in ...
Explains how to install and use parallel ssh (PSSH) tool for executing ssh in parallel on a number of hosts and automate many...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found