Replace wait with communicate to avoid potential deadlock

Wait can deadlock when using stdout=PIPE and/or stderr=PIPE and the child
process generates enough output to a pipe such that it blocks waiting for
the OS pipe buffer to accept more data. Use communicate() to avoid that.

Change-Id: I452de95834a18a970ae78ab6c43d794151ce3300
closes-bug: 1372680
This commit is contained in:
Aaron Rosen 2014-09-22 16:10:46 -07:00
parent 64fc93510e
commit 4fd9509b77
3 changed files with 6 additions and 9 deletions

View File

@ -624,7 +624,7 @@ class NeutronScenarioTest(ScenarioTest):
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait()
proc.communicate()
return (proc.returncode == 0) == should_succeed
return tempest.test.call_until_true(
@ -1832,7 +1832,7 @@ class NetworkScenarioTest(OfficialClientTest):
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait()
proc.communicate()
return (proc.returncode == 0) == should_succeed
return tempest.test.call_until_true(
@ -2267,7 +2267,7 @@ class OrchestrationScenarioTest(ScenarioTest):
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait()
proc.communicate()
return (proc.returncode == 0) == should_succeed
return tempest.test.call_until_true(

View File

@ -30,7 +30,7 @@ class FloatingStress(stressaction.StressAction):
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait()
proc.communicate()
success = proc.returncode == 0
return success

View File

@ -62,14 +62,11 @@ class TestWrappers(base.TestCase):
p = subprocess.Popen(
"bash %s" % cmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# wait in the general case is dangerous, however the amount of
# data coming back on those pipes is small enough it shouldn't be
# a problem.
p.wait()
out, err = p.communicate()
self.assertEqual(
p.returncode, expected,
"Stdout: %s; Stderr: %s" % (p.stdout.read(), p.stderr.read()))
"Stdout: %s; Stderr: %s" % (out, err))
def test_pretty_tox(self):
# Git init is required for the pbr testr command. pbr requires a git