From 3c6b72b452050800bef16b24092bdef58e6a3abd Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 7 Sep 2018 23:46:56 +0100 Subject: [PATCH] ansible: gracefully return (and explain) ChannelError in ContextService. When Ansible abnormally shuts down, the broker begins force-disconnecting every context, including those for which connection is currently in-progress. When that happens, .call(init_child) throws ChannelError, and that needs returned back to the worker, assuming the worker still even exists. This solution is incomplete: with sick nodes, it's also possible the worker died naturally, and so the worker should perhaps respond by retrying the connection. Previously, the unhandled ChannelError would spam the console when e.g. fork() began returning EAGAIN. --- ansible_mitogen/services.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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,