diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 5baba223..93ad0df6 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -356,7 +356,8 @@ class Connection(ansible.plugins.connection.ConnectionBase): executing. We use the opportunity to grab relevant bits from the task-specific data. """ - self.ansible_ssh_timeout = task_vars.get('ansible_ssh_timeout') + self.ansible_ssh_timeout = task_vars.get('ansible_ssh_timeout', + C.DEFAULT_TIMEOUT) self.python_path = task_vars.get('ansible_python_interpreter', '/usr/bin/python') self.mitogen_via = task_vars.get('mitogen_via') diff --git a/mitogen/parent.py b/mitogen/parent.py index 76ca50bd..7352712e 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -974,6 +974,8 @@ class Router(mitogen.core.Router): self._context_by_id[context_id] = context return context + connection_timeout_msg = "Connection timed out." + def _connect(self, klass, name=None, **kwargs): context_id = self.allocate_id() context = self.context_class(self, context_id) @@ -982,7 +984,11 @@ class Router(mitogen.core.Router): stream = klass(self, context_id, **kwargs) if name is not None: stream.name = name - stream.connect() + try: + stream.connect() + except mitogen.core.TimeoutError: + e = sys.exc_info()[1] + raise mitogen.core.StreamError(self.connection_timeout_msg) context.name = stream.name self.route_monitor.notice_stream(stream) self.register(context, stream)