diff --git a/ansible_mitogen/services.py b/ansible_mitogen/services.py index 952e991a..15c1e8b0 100644 --- a/ansible_mitogen/services.py +++ b/ansible_mitogen/services.py @@ -380,6 +380,12 @@ class ContextService(mitogen.service.Service): return latch + disconnect_msg = ( + 'Channel was disconnected while connection attempt was in progress; ' + 'this may be caused by an abnormal Ansible exit, or due to an ' + 'unreliable target.' + ) + @mitogen.service.expose(mitogen.service.AllowParents()) @mitogen.service.arg_spec({ 'stack': list @@ -407,6 +413,13 @@ class ContextService(mitogen.service.Service): if isinstance(result, tuple): # exc_info() reraise(*result) via = result['context'] + except mitogen.core.ChannelError: + return { + 'context': None, + 'init_child_result': None, + 'method_name': spec['method'], + 'msg': self.disconnect_msg, + } except mitogen.core.StreamError as e: return { 'context': None,