Improve nodescan worker cleanup
Rather than relying on __del__ to close the pipe fds, let's use the join() method which we should be calling during our shutdown procedure anyway. This will ensure the pipes are closed even if the object is not GC'd. Also, remove the backref from the request to the worker to increase the chances that the object can be GC'd. Change-Id: I71eb34b2502adebe7b3bf32eefb0fa540535f8f7
This commit is contained in:
@@ -327,6 +327,7 @@ class NodescanRequest:
|
||||
self.key_connection_failures,
|
||||
self.key_negotiation_failures,
|
||||
dt)
|
||||
self.worker = None
|
||||
|
||||
def result(self):
|
||||
"""Return the resulting keys, or raise an exception"""
|
||||
@@ -553,8 +554,7 @@ class NodescanWorker:
|
||||
MAX_REQUESTS = 100
|
||||
|
||||
def __init__(self):
|
||||
# Remember to close all pipes on __del__ to prevent leaks in
|
||||
# tests.
|
||||
# Remember to close all pipes to prevent leaks in tests.
|
||||
self.wake_read, self.wake_write = os.pipe()
|
||||
fcntl.fcntl(self.wake_read, fcntl.F_SETFL, os.O_NONBLOCK)
|
||||
self._running = False
|
||||
@@ -563,10 +563,6 @@ class NodescanWorker:
|
||||
self.poll = select.epoll()
|
||||
self.poll.register(self.wake_read, select.EPOLLIN)
|
||||
|
||||
def __del__(self):
|
||||
os.close(self.wake_read)
|
||||
os.close(self.wake_write)
|
||||
|
||||
def start(self):
|
||||
self._running = True
|
||||
self.thread = threading.Thread(target=self.run, daemon=True)
|
||||
@@ -578,6 +574,8 @@ class NodescanWorker:
|
||||
|
||||
def join(self):
|
||||
self.thread.join()
|
||||
os.close(self.wake_read)
|
||||
os.close(self.wake_write)
|
||||
|
||||
def addRequest(self, request):
|
||||
"""Submit a nodescan request"""
|
||||
|
||||
Reference in New Issue
Block a user