Unknown exception: cannot join current thread #354

Closed
jquast opened this Issue Jul 11, 2014 · 4 comments

Projects

None yet

2 participants

@jquast
Contributor
jquast commented Jul 11, 2014

068bf63 introduced self.join() in transport.py -- which causes spurious tracebacks on authentication failure because it is not possible to join your own thread, this raises RuntimeError("cannot join current thread") from threading.py.

To reproduce using demo_server.py, simply generate many public keys and fail with them all -- reaching the hard-coded limit of 10 ( in _send_auth_result of auth_handler.py.py.

client

$ for n in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do echo | ssh-keygen -f /tmp/_$n; done
$ ssh $(ls /tmp/_* | egrep '[0-9]$' | xargs -n 1 echo -i) -p 2200 user@localhost
Received disconnect from 127.0.0.1: 14: No more auth methods available

server

$ python demo_server.py
Read key: 60733844cb5186657fdedaa22b5a57d5
Listening for connection ...
Got a connection!
Auth attempt with key: c00d9692cde7305238cf7f57b720e8c3
Auth attempt with key: de86194ef717cf2e7da7697de33d2578
Auth attempt with key: 8a3c67327dea5d68f101d9455db2aa9b
Auth attempt with key: 4fb3989e5db919a139c32b96d69a71c1
Auth attempt with key: ddf541ef4b224588b37fa6976af4dcf0
Auth attempt with key: 7ef8e4532219a8b8439c1edeb625c0ef
Auth attempt with key: 02c5edc1a525fd241a29dca8dc3d959a
Auth attempt with key: a0715d805c164e14faddf9e45c00144b
Auth attempt with key: 4ce24af5ed716205dd83331560e61ce7
*** No channel.
$ cat demo_server.log
DEB [20140710-22:18:38.395] thr=1   paramiko.transport: starting thread (server mode): 0x98efad0L
INF [20140710-22:18:38.396] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_6.2)

...

DEB [20140710-22:18:38.419] thr=1   paramiko.transport: Auth request (type=publickey) service=ssh-connection, username=user
INF [20140710-22:18:38.419] thr=1   paramiko.transport: Auth rejected (publickey).

x10

ERR [20140710-22:18:38.419] thr=1   paramiko.transport: Unknown exception: cannot join current thread
ERR [20140710-22:18:38.420] thr=1   paramiko.transport: Traceback (most recent call last):
ERR [20140710-22:18:38.420] thr=1   paramiko.transport:   File "... paramiko/transport.py", line 1455, in run
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     self.auth_handler._handler_table[ptype](self.auth_handler, m)
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:   File "... paramiko/auth_handler.py", line 349, in _parse_userauth_request
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     self._send_auth_result(username, method, result)
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:   File "... paramiko/auth_handler.py", line 240, in _send_auth_result
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     self._disconnect_no_more_auth()
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:   File "... paramiko/auth_handler.py", line 144, in _disconnect_no_more_auth
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     self.transport.close()
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:   File "... paramiko/transport.py", line 498, in close
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     self.stop_thread()
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:   File "... paramiko/transport.py", line 1260, in stop_thread
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     self.join(10)
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:   File "... python2.7/threading.py", line 940, in join
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:     raise RuntimeError("cannot join current thread")
ERR [20140710-22:18:38.421] thr=1   paramiko.transport: RuntimeError: cannot join current thread
ERR [20140710-22:18:38.421] thr=1   paramiko.transport:

simplified example

>>> class T(threading.Thread):
...    def run(self):
...        self.join()
>>> T().start()
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.7_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "<ipython-input-6-e6c8a23b0b74>", line 3, in run
    self.join()
  File "/usr/local/Cellar/python/2.7.7_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 940, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
@bitprophet
Member

Folks are poking at this on IRC at the moment, but to clarify, the self.join was not introduced in the linked commit - it's been in the code since 2006 in one form or another.

So presuming that the line has always actually been wrong, which it is as far as we can tell - what has changed recently is probably more about whether and when the line actually gets executed. There've been at least a few shakeups to "closing out a transport" in the last year or so including the most recent one, #156 (which sourced the commit you linked originally.)

@bitprophet
Member

See #373 for potential fix, still being poked at.

@bitprophet
Member

I can confirm that the latest version of #373, merged into master, no longer raises the above RuntimeError. Closing this as "probably fixed", @jquast please comment if you get latest master or the 1.15 release (once it's out, should be today/tomorrow) and you're still having the real-world issue this was about. Thanks!

@bitprophet bitprophet closed this Sep 8, 2014
@jquast
Contributor
jquast commented Oct 27, 2014

late to the game, but I've updated to latest version and haven't seen this error in some time. Thanks.

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