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.
This commit is contained in:
parent
e5d421e5f4
commit
3c6b72b452
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue