diff --git a/changelog.rst b/changelog.rst index 2c3273ee..27629413 100644 --- a/changelog.rst +++ b/changelog.rst @@ -21,9 +21,11 @@ CHANGELOG - v.0.3.0 (`Pahaz`_) + Change default with context behavior to use `.stop(force=True)` on exit (is not fully backward compatible) + + Remove useless `daemon_forward_servers = True` hack for hangs prevention (is not fully backward compatible) + Set transport keepalive to 5 second by default (disabled for version < 0.3.0) + + Set default transport timeout to 0.1 + Deprecate and remove `block_on_close` option - + Drop `daemon_forward_servers = True` hack for "deadlocks" / "tunneling hangs" (`#173`_, `#201`_, `#162`_) + + Fix "deadlocks" / "tunneling hangs" (`#173`_, `#201`_, `#162`_, `#211`_) - v.0.2.2 (`Pahaz`_) + Add `.stop(force=True)` for force close active connections (`#201`_) @@ -161,4 +163,5 @@ CHANGELOG .. _#162: https://github.com/pahaz/sshtunnel/issues/162 .. _#173: https://github.com/pahaz/sshtunnel/issues/173 .. _#201: https://github.com/pahaz/sshtunnel/issues/201 +.. _#211: https://github.com/pahaz/sshtunnel/issues/211 .. _detail: https://github.com/pahaz/sshtunnel/commit/64af238b799b0e0057c4f9b386cda247e0006da9#diff-76bc1662a114401c2954deb92b740081R127 diff --git a/sshtunnel.py b/sshtunnel.py index adf48461..34d79f8d 100644 --- a/sshtunnel.py +++ b/sshtunnel.py @@ -40,21 +40,24 @@ __author__ = 'pahaz' -DEFAULT_LOGLEVEL = logging.ERROR #: default level if no logger passed (ERROR) -TUNNEL_TIMEOUT = 1.0 #: Timeout (seconds) for tunnel connection +#: Timeout (seconds) for transport socket (``socket.settimeout``) +SSH_TIMEOUT = 0.1 # ``None`` may cause a block of transport thread +#: Timeout (seconds) for tunnel connection (open_channel timeout) +TUNNEL_TIMEOUT = 1.0 + _DAEMON = False #: Use daemon threads in connections -TRACE_LEVEL = 1 _CONNECTION_COUNTER = 1 _LOCK = threading.Lock() -#: Timeout (seconds) for the connection to the SSH gateway, ``None`` to disable -SSH_TIMEOUT = None -DEPRECATIONS = { +_DEPRECATIONS = { 'ssh_address': 'ssh_address_or_host', 'ssh_host': 'ssh_address_or_host', 'ssh_private_key': 'ssh_pkey', 'raise_exception_if_any_forwarder_have_a_problem': 'mute_exceptions' } +# logging +DEFAULT_LOGLEVEL = logging.ERROR #: default level if no logger passed (ERROR) +TRACE_LEVEL = 1 logging.addLevelName(TRACE_LEVEL, 'TRACE') if os.name == 'posix': @@ -1180,12 +1183,17 @@ def _get_transport(self): _socket.settimeout(SSH_TIMEOUT) _socket.connect((self.ssh_host, self.ssh_port)) transport = paramiko.Transport(_socket) - if isinstance(transport.sock, socket.socket): - transport.sock.settimeout(SSH_TIMEOUT) + sock = transport.sock + if isinstance(sock, socket.socket): + sock.settimeout(SSH_TIMEOUT) transport.set_keepalive(self.set_keepalive) transport.use_compression(compress=self.compression) transport.daemon = self.daemon_transport - + if isinstance(sock, socket.socket): + sock_timeout = sock.gettimeout() + sock_info = repr((sock.family, sock.type, sock.proto)) + self.logger.debug('Transport socket info: {0}, timeout={1}' + .format(sock_info, sock_timeout)) return transport def _create_tunnels(self): @@ -1242,19 +1250,19 @@ def _process_deprecated(attrib, deprecated_attrib, kwargs): """ Processes optional deprecate arguments """ - if deprecated_attrib not in DEPRECATIONS: + if deprecated_attrib not in _DEPRECATIONS: raise ValueError('{0} not included in deprecations list' .format(deprecated_attrib)) if deprecated_attrib in kwargs: warnings.warn("'{0}' is DEPRECATED use '{1}' instead" .format(deprecated_attrib, - DEPRECATIONS[deprecated_attrib]), + _DEPRECATIONS[deprecated_attrib]), DeprecationWarning) if attrib: raise ValueError("You can't use both '{0}' and '{1}'. " "Please only use one of them" .format(deprecated_attrib, - DEPRECATIONS[deprecated_attrib])) + _DEPRECATIONS[deprecated_attrib])) else: return kwargs.pop(deprecated_attrib) return attrib diff --git a/tests/test_forwarder.py b/tests/test_forwarder.py index 37556083..78a11d3e 100644 --- a/tests/test_forwarder.py +++ b/tests/test_forwarder.py @@ -689,7 +689,7 @@ def test_deprecate_warnings_are_shown(self): open_tunnel(**_kwargs) logged_message = "'{0}' is DEPRECATED use '{1}' instead"\ .format(deprecated_arg, - sshtunnel.DEPRECATIONS[deprecated_arg]) + sshtunnel._DEPRECATIONS[deprecated_arg]) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) self.assertEqual(logged_message, str(w[-1].message)) @@ -709,7 +709,7 @@ def test_deprecate_warnings_are_shown(self): open_tunnel(**_kwargs) logged_message = "'{0}' is DEPRECATED use '{1}' instead"\ .format(deprecated_arg, - sshtunnel.DEPRECATIONS[deprecated_arg]) + sshtunnel._DEPRECATIONS[deprecated_arg]) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) self.assertEqual(logged_message, str(w[-1].message))