# Race condition in async mode?

**URL:** <https://forum.ansible.com/t/race-condition-in-async-mode/11384>\
**Category:** Ansible Project\
**Created:** [March 30, 2012, 9:45pm UTC](https://forum.ansible.com/t/race-condition-in-async-mode/11384 "2012-03-30T21:45:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Gaarder](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Steve\_Gaarder](https://forum.ansible.com/u/Steve_Gaarder)\
**Post date:** [March 30, 2012, 9:45pm UTC](https://forum.ansible.com/t/race-condition-in-async-mode/11384/1 "2012-03-30T21:45:27Z")

</div>

I tried running a simple playbook with the yum module run  
asynchronously. Some of the time, I get this error:

failed: [hardy1] =\> {"ansible\_job\_id": "269083845912", "failed": 1,  
"finished": 1, "msg": "Argument file not found"}

I think it's a race condition, where the temporary directory is  
removed before the async wrapper is finished. If, in runner.py, I  
sleep for 1 second right before "self.\_delete\_remote\_files(conn, tmp)"  
I do not see the problem. But there must be a better fix - any ideas?

My playbook:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 30, 2012, 10:08pm UTC](https://forum.ansible.com/t/race-condition-in-async-mode/11384/2 "2012-03-30T22:08:58Z")

</div>

To be more clear, while async wrapper starts a background process, the async\_status module is not actually asynchronous at all, just  
run often in a loop.

(Thus it shouldn’t be subject to deletion… UNLESS the tempdir name is calculated and reused between async\_wrapper and async\_runs,  
in which case, we should take efforts to not do that.)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 31, 2012, 4:47pm UTC](https://forum.ansible.com/t/race-condition-in-async-mode/11384/3 "2012-03-31T16:47:24Z")

</div>

Just wanted to share that I can in fact reproduce this with the attached playbook.

It doesn’t look like the tempdir files are reused (which was my theory), but just that async poll runs in the meantime between async\_wrapper writing the initial JID started file and the yum command (which finishes very quickly) trying to rewrite the file.

The solution seems to be incorporating some try/wait logic in async\_wrapper but I’ll have to dig a little. Should be pretty simple to fix.

(The workaround, for now, is to not use async unless you really need to, this particular task doesn’t benefit from async polling, a command that would take 20 minutes would)
