From df69892827e12db0379758de0a021e129b7b1d8e Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Tue, 14 Apr 2020 11:18:10 +0200 Subject: [PATCH] Ensure deletion of the command socket The command socket class currently deletes the command socket after joining its worker thread. Make this more safe by moving the deletion at the end of the worker thread. Change-Id: I5170cad933f465cd7ba0485d2add8699c20c6679 --- zuul/lib/commandsocket.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zuul/lib/commandsocket.py b/zuul/lib/commandsocket.py index 96dddb6c4a..040ac9f300 100644 --- a/zuul/lib/commandsocket.py +++ b/zuul/lib/commandsocket.py @@ -55,9 +55,6 @@ class CommandSocket(object): # re-entering their loop. self.queue.put(b'_stop') self.socket_thread.join() - self.socket.close() - if os.path.exists(self.path): - os.unlink(self.path) def _socketListener(self): while self.running: @@ -80,6 +77,12 @@ class CommandSocket(object): except Exception: self.log.exception("Exception in socket handler") + # Unlink socket file within the thread so join works and we don't + # leak the socket file. + self.socket.close() + if os.path.exists(self.path): + os.unlink(self.path) + def get(self): if not self.running: raise Exception("CommandSocket.get called while stopped")