From 2174230315323b8e0da11480c82f5037fc2e2fc2 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Tue, 27 Aug 2013 14:32:39 -0400 Subject: [PATCH] USE subprocess.Popen API correctly. When collecting stdout/stderr *and* feeding data into a Popen instance, communicate() must be used to avoid a known deadlocking scenario when data sizes cross PIPE_BUF (which can be as small as 512, although should be much larger in practice on linux). --- lib/ansible/module_common.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 91b2c4d9b8..648af8ff28 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -935,10 +935,9 @@ class AnsibleModule(object): stdout=subprocess.PIPE, stderr=subprocess.PIPE) if data: - cmd.stdin.write(data) if not binary_data: - cmd.stdin.write('\\n') - out, err = cmd.communicate() + data += '\\n' + out, err = cmd.communicate(input=data) rc = cmd.returncode except (OSError, IOError), e: self.fail_json(rc=e.errno, msg=str(e), cmd=args)