From d2a7be142e1436981f985ab896d603e8a9396a0d Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 18 Apr 2016 11:51:45 -0700 Subject: [PATCH] A couple fixes for ziploader: * Move zipcache temp dir creation into the locked section otherwise it races with other workers. * Catch IOError and turn it into an AnsibleError. IOErrors can hang multiprocessng. --- lib/ansible/executor/module_common.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py index fb9eb04d4c..539da53da8 100644 --- a/lib/ansible/executor/module_common.py +++ b/lib/ansible/executor/module_common.py @@ -385,8 +385,6 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta compression_method = zipfile.ZIP_STORED lookup_path = os.path.join(C.DEFAULT_LOCAL_TMP, 'ziploader_cache') - if not os.path.exists(lookup_path): - os.mkdir(lookup_path) cached_module_filename = os.path.join(lookup_path, "%s-%s" % (module_name, module_compression)) zipdata = None @@ -416,6 +414,10 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta # Write the assembled module to a temp file (write to temp # so that no one looking for the file reads a partially # written file) + if not os.path.exists(lookup_path): + # Note -- if we have a global function to setup, that would + # be a better place to run this + os.mkdir(lookup_path) with open(cached_module_filename + '-part', 'w') as f: f.write(zipdata) @@ -428,7 +430,10 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta # Another process wrote the file while we were waiting for # the write lock. Go ahead and read the data from disk # instead of re-creating it. - zipdata = open(cached_module_filename, 'rb').read() + try: + zipdata = open(cached_module_filename, 'rb').read() + except IOError: + raise AnsibleError('A different worker process failed to create module file. Look at traceback for that process for debugging information.') # Fool the check later... I think we should just remove the check snippet_names.add('basic') shebang, interpreter = _get_shebang(u'/usr/bin/python', task_vars)