EOFError when threading

Bug #567330 reported by xvalentinex
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
paramiko
New
Undecided
Unassigned

Bug Description

When threading multiple SSH sessions Transport.get_exception() will randomly return an EOFError when executing Transport.open_session() on a second Channel.exec_command().

Example:

class Router(Thread):
        tlist = []
        lock = Lock()

        def __init__(self, login):
                Thread.__init__(self)
                self.login = login
                self.ssh = paramiko.SSHClient()
                self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        def run(self):
                try:
                        self.ssh.connect(timeout=20, **self.login)
                        stdin, stdout, stderr = self.ssh.exec_command('command1')
                        # Do something with stdout
                        stdin, stdout, stderr = self.exec_command('command2')
                        # Radomly raises EOFError on some threads, other threads will work as expected
                finally:
                        self.ssh.close()

if __name__ == '__main__':
        for rtr, login in ROUTERS.items():
                Router.lock.acquire()
                rtr = Router(login)
                Router.tlist.append(rtr)
                rtr.setName(name)
                Router.lock.release()
                rtr.start()
        for rtr in Router.tlist:
                rtr.join()

If I go lower and use SSHClient only for connecting then get_transport, and open_session I will have the same result. However, if I create two channels using open_session before running an exec_command on either, it will work as expected without an EOFError.

Example that works:
tran = self.ssh.get_transport()
chan1 = tran.open_session()
chan2 = tran.open_session()
chan1.exec_command('command1')
# Do something with chan1.makefile
chan2.exec_command('command2')
# Do something with chan2.makefile

Example that will raise random EOFErrors:
tran = self.ssh.get_transport()
chan = tran.open_session()
chan.exec_command('command1')
# Do something with chan.makefile
chan = tran.open_session()
# Raises random EOFErrors

Also if I limit the thread count to 1 using Event() everything works as expected, but if I limit the thread count to anything over 1 I see the random EOFErrors.

I would be happy to provide more details if needed.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.