Skip to content

[BUG] - SSH exec_command gets stuck while waiting for threading Event #2599

Open

Description

@shubhanshu02

Are you using paramiko as a client or server?

Client

What feature(s) aren't working right?

SSH

What version(s) of paramiko are you using?

3.5.1

What version(s) of Python are you using?

3.8.10

What operating system and version are you using?

Ubuntu 20

If you're connecting as a client, which SSH server are you connecting to?

No response

If you're using paramiko as part of another tool, which tool/version?

No response

Expected/desired behavior

In some of my applications that have long running SSH connections, sometimes the exec_command() function call in SSHClient gets stuck indefinitely, causing the entire process to get blocked.

I went through the code and found that exec_command uses self.event.wait() directly without passing the timeout parameter, which is the root cause for this issue. Code reference mentioned below:

paramiko/paramiko/channel.py

Lines 1216 to 1225 in 8697158

def _wait_for_event(self):
self.event.wait()
assert self.event.is_set()
if self.event_ready:
return
e = self.transport.get_exception()
if e is None:
e = SSHException("Channel closed.")
raise e

Actual behavior

We should be passing timeout here as well to avoid getting stuck indefinitely. Python threading library already exposes a timeout parameter which should be used here.

Ref: https://docs.python.org/3/library/threading.html#threading.Event.wait

How to reproduce

No response

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions