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.
pull/372/head
David Wilson 6 years ago
parent e5d421e5f4
commit 3c6b72b452

@ -380,6 +380,12 @@ class ContextService(mitogen.service.Service):
return latch 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.expose(mitogen.service.AllowParents())
@mitogen.service.arg_spec({ @mitogen.service.arg_spec({
'stack': list 'stack': list
@ -407,6 +413,13 @@ class ContextService(mitogen.service.Service):
if isinstance(result, tuple): # exc_info() if isinstance(result, tuple): # exc_info()
reraise(*result) reraise(*result)
via = result['context'] 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: except mitogen.core.StreamError as e:
return { return {
'context': None, 'context': None,

Loading…
Cancel
Save