diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2016-06-12 11:24:13 -0700 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2016-06-12 11:24:13 -0700 |
commit | b8236a4cfc0539cf9932a9265659679bfae88d8c (patch) | |
tree | 668bd32c25c7f98fb37e702f68f9e892db638ebd | |
parent | ac8c382bf2224e346fff63f5cd36920d359908ef (diff) | |
parent | 3a13b43a0d15b9af10a8106574d91397d18faa07 (diff) |
Merge branch '2.0'
-rw-r--r-- | paramiko/transport.py | 30 | ||||
-rw-r--r-- | tests/loop.py | 2 |
2 files changed, 20 insertions, 12 deletions
diff --git a/paramiko/transport.py b/paramiko/transport.py index 000a98f3..9fcaa9fb 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -58,7 +58,7 @@ from paramiko.kex_gss import KexGSSGex, KexGSSGroup1, KexGSSGroup14, NullHostKey from paramiko.message import Message from paramiko.packet import Packetizer, NeedRekeyException from paramiko.primes import ModulusPack -from paramiko.py3compat import string_types, long, byte_ord, b, input +from paramiko.py3compat import string_types, long, byte_ord, b, input, PY2 from paramiko.rsakey import RSAKey from paramiko.ecdsakey import ECDSAKey from paramiko.server import ServerInterface @@ -1533,17 +1533,23 @@ class Transport (threading.Thread, ClosingContextManager): def stop_thread(self): self.active = False self.packetizer.close() - # Keep trying to join() our main thread, quickly, until: - # * We join()ed successfully (self.is_alive() == False) - # * Or it looks like we've hit issue #520 (socket.recv hitting some - # race condition preventing it from timing out correctly), wherein our - # socket and packetizer are both closed (but where we'd otherwise be - # sitting forever on that recv()). - while ( - self.is_alive() and self is not threading.current_thread() - and not self.sock._closed and not self.packetizer.closed - ): - self.join(0.1) + if PY2: + # Original join logic; #520 doesn't appear commonly present under + # Python 2. + while self.is_alive() and self is not threading.current_thread(): + self.join(10) + else: + # Keep trying to join() our main thread, quickly, until: + # * We join()ed successfully (self.is_alive() == False) + # * Or it looks like we've hit issue #520 (socket.recv hitting some + # race condition preventing it from timing out correctly), wherein + # our socket and packetizer are both closed (but where we'd + # otherwise be sitting forever on that recv()). + while ( + self.is_alive() and self is not threading.current_thread() + and not self.sock._closed and not self.packetizer.closed + ): + self.join(0.1) ### internals... diff --git a/tests/loop.py b/tests/loop.py index 4f5dc163..e805ad96 100644 --- a/tests/loop.py +++ b/tests/loop.py @@ -37,9 +37,11 @@ class LoopSocket (object): self.__cv = threading.Condition(self.__lock) self.__timeout = None self.__mate = None + self._closed = False def close(self): self.__unlink() + self._closed = True try: self.__lock.acquire() self.__in_buffer = bytes() |