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")