Fix race in test_bubblewrap_leak

proc entries can be removed during this list comprehension

Change-Id: I6b981b539090dba22636778ab72304eace2c0226
This commit is contained in:
James E. Blair 2018-04-26 15:37:50 -07:00
parent 9bf871168f
commit fd8896958f
1 changed files with 6 additions and 3 deletions

View File

@ -70,9 +70,12 @@ class TestBubblewrap(testtools.TestCase):
self.assertEqual(0, true_proc.wait())
cmdline = "sleep\x000x%X\x00" % leak_time
for x in iterate_timeout(30, "process to exit"):
sleep_proc = [pid for pid in os.listdir("/proc") if
os.path.isfile("/proc/%s/cmdline" % pid) and
open("/proc/%s/cmdline" % pid).read() == cmdline]
try:
sleep_proc = [pid for pid in os.listdir("/proc") if
os.path.isfile("/proc/%s/cmdline" % pid) and
open("/proc/%s/cmdline" % pid).read() == cmdline]
except FileNotFoundError:
pass
if not sleep_proc:
break
time.sleep(1)