make fileserverclient.close fully robust

Test Plan: ran tests

Reviewers: durham

Reviewed By: durham

Differential Revision: https://phabricator.fb.com/D2544243

Signature: t1:2544243:1444883084:a7b9cc9167a7671e34813826ba9fcd289919afd1
This commit is contained in:
Ryan McElroy 2015-10-14 18:49:55 -07:00
parent f8360b4766
commit 9943d04f51

View File

@ -67,35 +67,31 @@ class cacheconnection(object):
self.connected = True
def close(self):
self.connected = False
# if the process is still open, terminate it
# close the pipes
if self.pipei:
def tryclose(pipe):
try:
pipe.close()
except:
pass
if self.connected:
try:
self.pipei.write("exit\n")
except:
pass
try:
self.pipei.close()
finally:
tryclose(self.pipei)
self.pipei = None
if self.pipeo:
try:
self.pipeo.close()
finally:
tryclose(self.pipeo)
self.pipeo = None
if self.pipee:
try:
self.pipee.close()
finally:
tryclose(self.pipee)
self.pipee = None
try:
# Wait for process to terminate, making sure to avoid deadlock. See
# https://docs.python.org/2/library/subprocess.html#popen-objects
# for warnings about wait() and
# Wait for process to terminate, making sure to avoid deadlock.
# See https://docs.python.org/2/library/subprocess.html for
# warnings about wait() and deadlocking.
self.subprocess.communicate()
finally:
except:
pass
self.subprocess = None
self.connected = False
def request(self, request, flush=True):
if self.connected: