From 45b748833daa6031674c7e0240a4bf5b138d7500 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 10 Jun 2018 15:25:11 +0100 Subject: [PATCH] ansible: don't randomly fail due to temp directory cleanup. Happens about 1 time in 3 when async task times out. --- ansible_mitogen/runner.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index e14d26bd..7155aee1 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -38,6 +38,7 @@ how to build arguments for it, preseed related data, etc. from __future__ import absolute_import import cStringIO import ctypes +import errno import imp import json import logging @@ -148,7 +149,7 @@ class Runner(object): implementation simply restores the original environment. """ self._env.revert() - self._cleanup_temp() + self._try_cleanup_temp() def _cleanup_temp(self): """ @@ -162,6 +163,20 @@ class Runner(object): LOG.debug('Deleting %r', path) ansible_mitogen.target.prune_tree(path) + def _try_cleanup_temp(self): + """ + During broker shutdown triggered by async task timeout or loss of + connection to the parent, it is possible for prune_tree() in + target.py::_on_broker_shutdown() to run before _cleanup_temp(), so skip + cleanup if the directory or a file disappears from beneath us. + """ + try: + self._cleanup_temp() + except (IOError, OSError) as e: + if e.args[0] == errno.ENOENT: + return + raise + def _run(self): """ The _run() method is expected to return a dictionary in the form of