Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Use os.rename() in async_wrapper #4051

Merged
merged 1 commit into from
Jul 7, 2016
Merged

Use os.rename() in async_wrapper #4051

merged 1 commit into from
Jul 7, 2016

Conversation

Shrews
Copy link
Contributor

@Shrews Shrews commented Jun 27, 2016

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

utilities/logic/async_wrapper.py

ANSIBLE VERSION
ansible 2.2.0 (devel c117b9d79b) last updated 2016/06/23 16:39:30 (GMT -400)
  lib/ansible/modules/core: (detached HEAD 4fe583e29b) last updated 2016/06/23 16:39:38 (GMT -400)
  lib/ansible/modules/extras: (detached HEAD 709114d55f) last updated 2016/06/23 16:39:38 (GMT -400)

This should probably be backported to 2.1 as well.

SUMMARY

Because the async_status module will read from the same file that
the async_wrapper module is writing, it's possible that the file
may not be fully synced during a read, causing spurious failures.
Use a temp file to do an atomic operation on the file. We can't
use atomic_move() here as that doesn't work properly under async.

Also, let's not read concurrently from the same file the subprocess
is writing to. Instead, capture stdout/stderr via PIPE and write to
the file to avoid nasty races.

@gregdek
Copy link
Contributor

gregdek commented Jun 27, 2016

Thanks @Shrews for this PR. This PR requires revisions, either because it fails to build or by reviewer request. Please make the suggested revisions. When you are done, please comment with text 'ready_for_review' and we will put this PR back into review.

[This message brought to you by your friendly Ansibull-bot.]

@@ -104,7 +108,9 @@ def _run_module(wrapped_cmd, jid, job_path):
}
result['ansible_job_id'] = jid
jobfile.write(json.dumps(result))
jobfile.close()
finally:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try/except/finally won't work with 2.4

Because the async_status module will read from the same file that
the async_wrapper module is writing, it's possible that the file
may not be fully synced during a read, causing spurious failures.
Use a temp file to do an atomic operation on the file. We can't
use atomic_move() here as that doesn't work properly under async.

Also, let's not read concurrently from the same file the subprocess
is writing to. Instead, capture stdout/stderr via PIPE and write to
the file to avoid nasty races.
@Shrews
Copy link
Contributor Author

Shrews commented Jun 29, 2016

ready_for_review

@gregdek
Copy link
Contributor

gregdek commented Jun 29, 2016

Thanks @Shrews for this PR. This module is maintained by the Ansible core team, so it can take a while for patches to be reviewed. Thanks for your patience.

Core team: please review according to guidelines (http://docs.ansible.com/ansible/developing_modules.html#module-checklist) and comment with 'needs_revision' or merge as appropriate.

[This message brought to you by your friendly Ansibull-bot.]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants