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
This commit is contained in:
Tobias Henkel
2020-04-14 11:18:10 +02:00
parent 28a23df468
commit df69892827
+6 -3
View File
@@ -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")