You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
paramiko.ssh_exception.SSHException: Unable to open channel. #1508
I am using paramiko==2.6.0 for ssh connection from one device to another. For almost all the time I was successful in establishing the connection when executing any command on remote Linux device. However, for one instance the connection failed with below error.
_, stdout, stderr = self.sshObj.exec_command(psCommand)
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 508, in exec_command
chan = self._transport.open_session(timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 879, in open_session
timeout=timeout,
File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 1006, in open_channel
raise e
paramiko.ssh_exception.SSHException: Unable to open channel.
I have experienced this as well. I am using paramiko to ping a linux cluster for job completion every 10s. It seems like it is the volume of subsequent calls that is causing the error. Any ideas on this issue?
This is new to me (though I haven't searched tracker for other examples of it yet). If someone who's able to reproduce this can try a few different versions of Paramiko, and also provide details about their local and remote ends (eg which version of remote sshd is this, etc) that might help us narrow it down or reproduce.
It seems the intent was to do something along these lines (patch):
start_ts = time.time()
while True:
event.wait(0.1)
if not self.active:
e = self.get_exception()
if e is not None:
raise e
if event.is_set():
break
elif start_ts + timeout < time.time():
raise SSHException("Timeout opening channel")
The default timeout of 3600s might be too long, but that's probably a separate discussion from having a timeout of 0.1s which we have now.
Alternatively, if the intent was to have a timeout of 0.1s, the entire "while True" loop can be scrapped, and "Unable to open channel" exception can be replaced with "Timeout opening channel", with the timeout being whatever time is passed into event.wait(). The "if event.is_set()" is also unneeded in that case, since there is nothing to break out of. Threading.event documentation suggests that event.wait() will return True if the flag has been set, and something else if it has timed out.
I am assuming that another thread that establishes a connection will call event.set() once done, and it only has those 0.1s to do it: I haven't dove deeper into code.
Upon further reading, I can see that it does loop if SSH connection is already active. So perhaps it's the callsite's responsibility to ensure that the SSH connection has been established and the transport is active before attempting to open_channel()s?
In that case, it would be good to communicate that with an error message instead: "raise SSHException('Transport not active yet')" instead of the "Unable to open channel".
And for some final context, we are using fabric2 to manage a bunch of runners, and they sometime fail with "Unable to open channel". It seems the problem is that it is transport become inactive while attempting to open channels (using open_session). While it's a bit confusing how transport can become inactive (only stop_thread() sets self.active = False), there seems to be an issue somewhere (perhaps in the fabric Connection.exit()).
Have the same issue when a parallel job trying to connect to different hosts and execute task. The issue did not appear at the beginning. And it seems no relationship with timeout because some tasks succeeded with a longer execution time(for example: more than 1 hour) and some failed in a short time(17 mins).
It works well in single execution.
Any thought or workaround to fix the issue?
Error:
packages/paramiko/transport.py", line 1006, in open_channel
paramiko.ssh_exception.SSHException: Unable to open channel.
background: we switched fabric from 1.14.1 to 2.5.0. In fab1, we do not have such issue in parallel job.
fabric=2.5.0
invoke==1.4.1
paramiko==2.6.0
More trace info:
22:32:49 result = self.conn.run(cmd, warn=True, hide=True)
22:32:49 File "", line 2, in run
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 30, in opens
22:32:49 return method(self, *args, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 721, in run
22:32:49 return self._run(self._remote_runner(), command, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/invoke/context.py", line 101, in _run
22:32:49 return runner.run(command, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/invoke/runners.py", line 363, in run
22:32:49 return self._run_body(command, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/invoke/runners.py", line 411, in _run_body
22:32:49 self.start(command, self.opts["shell"], self.env)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/runners.py", line 36, in start
22:32:49 self.channel = self.context.create_session()
22:32:49 File "", line 2, in create_session
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 30, in opens
22:32:49 return method(self, *args, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 698, in create_session
22:32:49 channel = self.transport.open_session()
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/paramiko/transport.py", line 879, in open_session
22:32:49 timeout=timeout,
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/paramiko/transport.py", line 1006, in open_channel
22:32:49 raise e
22:32:49 paramiko.ssh_exception.SSHException: Unable to open channel
Comments on #1705 imply that the issue is only reliably reproduced on Python 2.7, which is no longer in scope. If one of y'all can confirm steps to reliably repro under Python 3.6+, I'll take a look at importing the alleged fix from paramiko-ng. Thanks!
I will rebuild my app with Python 3.10 and redeploy at the sites where I’m
getting this error the most.
As far as “reliably reproduce”, I don’t know how.
Actually I just checked and my most problematic install is already running
on python 3.11 and got this recently:
ALARM: Unhandled exception in watch_linux.Linux:
Traceback (most recent call last):
File "watch.py", line 385, in check_and_notify
File "watch_linux.py", line 62, in check
File "watch_linux.py", line 153, in _check_time
File "watch_linux.py", line 189, in _exec
File "paramiko\client.py", line 510, in exec_command
File "paramiko\transport.py", line 920, in open_session
File "paramiko\transport.py", line 1051, in open_channel
paramiko.ssh_exception.SSHException: Unable to open channel.
EDIT: removed email signature
On Fri, Jan 27, 2023 at 5:36 PM Royce Mitchell III ***@***.***> wrote:
I will rebuild my app with Python 3.10 and redeploy at the sites where I’m
getting this error the most.
As far as “reliably reproduce”, I don’t know how.
On Fri, Jan 27, 2023 at 5:35 PM Jeff Forcier ***@***.***>
wrote:
> Comments on #1705 <#1705>
> imply that the issue is only reliably reproduced on Python 2.7, which is no
> longer in scope. If one of y'all can confirm steps to reliably repro under
> Python 3.6+, I'll take a look at importing the alleged fix from
> paramiko-ng. Thanks!
>
> —
> Reply to this email directly, view it on GitHub
> <#1508 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AA4RVV7UQ5XG4XVQJZVTQ33WURLSHANCNFSM4IWQXERA>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
--
Ploxiln also noted he was unable to repro under Python 3 here
I ran that script (which, to be fair, is just the base case of "connect, run command, loop") for 30 minutes so far (which must have been many thousands of iterations) and zero explosions :(
@remdragon and others - if you can give me a better idea of your local parameters for reproducing under Python 3 (eg a similar test script as in that other ticket, or at least something like "we're seeing it every N connection attempts" so I have some idea of a reasonable upper bound) that'd be ideal, because I'm still very loathe to patch a critical code path for an issue that I cannot personally reproduce.
So luckily this script still exists randomly on my work computer's home directory.
I ran it the first time and nothing happened within 5-10 minutes.
I ran it again without restarting sshd and switched my focus and it did indeed fail, sometime within 30 minutes:
$ python3 test_ssh.py
Traceback (most recent call last):
File "test_ssh.py", line 44, in <module>
raise caught_exception
File "/home/gpalmer/python/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "test_ssh.py", line 36, in run_command_in_thread
raise e
File "test_ssh.py", line 21, in run_command_in_thread
ret = ssh.exec_command(cmd)
File "/home/gpalmer/python/lib/python3.8/site-packages/paramiko/client.py", line 516, in exec_command
chan.exec_command(command)
File "/home/gpalmer/python/lib/python3.8/site-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/home/gpalmer/python/lib/python3.8/site-packages/paramiko/channel.py", line 257, in exec_command
self._wait_for_event()
File "/home/gpalmer/python/lib/python3.8/site-packages/paramiko/channel.py", line 1226, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
And in the sshd window:
channel_by_id: 2: bad id: channel free
Disconnecting user gpalmer ::1 port 58238: ieof packet referred to nonexistent channel 2
I'm running Python 3.8.5 and pip show paramiko yields:
Activity
timothy-thomas commentedon Dec 5, 2019
I have experienced this as well. I am using paramiko to ping a linux cluster for job completion every 10s. It seems like it is the volume of subsequent calls that is causing the error. Any ideas on this issue?
bitprophet commentedon Dec 9, 2019
This is new to me (though I haven't searched tracker for other examples of it yet). If someone who's able to reproduce this can try a few different versions of Paramiko, and also provide details about their local and remote ends (eg which version of remote sshd is this, etc) that might help us narrow it down or reproduce.
dsegan commentedon Feb 20, 2020
I believe the problem is the "timeout loop" at https://github.com/paramiko/paramiko/blob/master/paramiko/transport.py#L1000 — effectively, it does not loop at all. If connection is established in the initial event.wait(0.1), it succeeds, otherwise it fails with SSHException("Unable to open channel.").
It seems the intent was to do something along these lines (patch):
The default timeout of 3600s might be too long, but that's probably a separate discussion from having a timeout of 0.1s which we have now.
There might be a similar problem on https://github.com/paramiko/paramiko/blob/master/paramiko/transport.py#L1132
dsegan commentedon Feb 20, 2020
Alternatively, if the intent was to have a timeout of 0.1s, the entire "while True" loop can be scrapped, and "Unable to open channel" exception can be replaced with "Timeout opening channel", with the timeout being whatever time is passed into event.wait(). The "if event.is_set()" is also unneeded in that case, since there is nothing to break out of. Threading.event documentation suggests that event.wait() will return True if the flag has been set, and something else if it has timed out.
I am assuming that another thread that establishes a connection will call event.set() once done, and it only has those 0.1s to do it: I haven't dove deeper into code.
dsegan commentedon Feb 20, 2020
Upon further reading, I can see that it does loop if SSH connection is already active. So perhaps it's the callsite's responsibility to ensure that the SSH connection has been established and the transport is active before attempting to open_channel()s?
In that case, it would be good to communicate that with an error message instead: "raise SSHException('Transport not active yet')" instead of the "Unable to open channel".
dsegan commentedon Feb 20, 2020
And for some final context, we are using fabric2 to manage a bunch of runners, and they sometime fail with "Unable to open channel". It seems the problem is that it is transport become inactive while attempting to open channels (using open_session). While it's a bit confusing how transport can become inactive (only stop_thread() sets self.active = False), there seems to be an issue somewhere (perhaps in the fabric Connection.exit()).
stanislavkozlovski commentedon Aug 4, 2020
Seeing the same thing
phocheng commentedon Sep 21, 2020
Have the same issue when a parallel job trying to connect to different hosts and execute task. The issue did not appear at the beginning. And it seems no relationship with timeout because some tasks succeeded with a longer execution time(for example: more than 1 hour) and some failed in a short time(17 mins).
It works well in single execution.
Any thought or workaround to fix the issue?
Error:
packages/paramiko/transport.py", line 1006, in open_channel
paramiko.ssh_exception.SSHException: Unable to open channel.
background: we switched fabric from 1.14.1 to 2.5.0. In fab1, we do not have such issue in parallel job.
fabric=2.5.0
invoke==1.4.1
paramiko==2.6.0
phocheng commentedon Sep 22, 2020
More trace info:
22:32:49 result = self.conn.run(cmd, warn=True, hide=True)
22:32:49 File "", line 2, in run
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 30, in opens
22:32:49 return method(self, *args, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 721, in run
22:32:49 return self._run(self._remote_runner(), command, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/invoke/context.py", line 101, in _run
22:32:49 return runner.run(command, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/invoke/runners.py", line 363, in run
22:32:49 return self._run_body(command, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/invoke/runners.py", line 411, in _run_body
22:32:49 self.start(command, self.opts["shell"], self.env)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/runners.py", line 36, in start
22:32:49 self.channel = self.context.create_session()
22:32:49 File "", line 2, in create_session
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 30, in opens
22:32:49 return method(self, *args, **kwargs)
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/fabric/connection.py", line 698, in create_session
22:32:49 channel = self.transport.open_session()
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/paramiko/transport.py", line 879, in open_session
22:32:49 timeout=timeout,
22:32:49 File "/home/jenkins/venv/lib/python2.7/site-packages/paramiko/transport.py", line 1006, in open_channel
22:32:49 raise e
22:32:49 paramiko.ssh_exception.SSHException: Unable to open channel
phocheng commentedon Sep 29, 2020
@bitprophet would you please take a look at the issue? any suggestion or workaround to fix this kind of issue?
sivachandranp commentedon Nov 25, 2020
Is this issue got fixed? Im using paramiko 2.7.1 version.
phocheng commentedon Nov 25, 2020
same question. Do we have any estimate about the fixing? Or, do we have any quick workaround?
remdragon commentedon Apr 15, 2021
I am also being affected by this bug. Is there an ETA? Thanks!
12 remaining items
bitprophet commentedon Jan 27, 2023
Comments on #1705 imply that the issue is only reliably reproduced on Python 2.7, which is no longer in scope. If one of y'all can confirm steps to reliably repro under Python 3.6+, I'll take a look at importing the alleged fix from paramiko-ng. Thanks!
remdragon commentedon Jan 27, 2023
remdragon commentedon Jan 27, 2023
bitprophet commentedon Mar 10, 2023
I tried reproducing this and still cannot under Python 3:
@remdragon and others - if you can give me a better idea of your local parameters for reproducing under Python 3 (eg a similar test script as in that other ticket, or at least something like "we're seeing it every N connection attempts" so I have some idea of a reasonable upper bound) that'd be ideal, because I'm still very loathe to patch a critical code path for an issue that I cannot personally reproduce.
gtpalmer commentedon Mar 10, 2023
So luckily this script still exists randomly on my work computer's home directory.
I ran it the first time and nothing happened within 5-10 minutes.
I ran it again without restarting sshd and switched my focus and it did indeed fail, sometime within 30 minutes:
And in the sshd window:
I'm running Python 3.8.5 and
pip show paramikoyields:gtpalmer commentedon Mar 10, 2023
Also the sshd I'm running is part of
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020Add retry for SSHException due to paramiko/paramiko#1508 (#327)
[ssh] Revert enabling test_ssh_stress on vpp (sonic-net#27720)
[conditional_mark] Remove redundant vs t1/t2 skip for ssh/test_ssh_st…
[conditional_mark] Remove redundant vs t1/t2 skip for ssh/test_ssh_st…