diff --git a/nodepool/driver/static/provider.py b/nodepool/driver/static/provider.py index 8f03075bb..3b8659ad5 100644 --- a/nodepool/driver/static/provider.py +++ b/nodepool/driver/static/provider.py @@ -443,19 +443,26 @@ class StaticNodeProvider(Provider, QuotaSupport): def cleanupLeakedResources(self): if self._idle: return + with self._register_lock: self.getRegisteredNodes() - for pool in self.provider.pools.values(): - for static_node in pool.nodes: - try: - self.syncNodeCount(static_node, pool) - except StaticNodeError as exc: - self.log.warning("Couldn't sync node: %s", exc) - continue - except Exception: - self.log.exception("Couldn't sync node %s:", - nodeTuple(static_node)) - continue + with ThreadPoolExecutor() as executor: + for pool in self.provider.pools.values(): + synced_nodes = [] + for static_node in pool.nodes: + synced_nodes.append((static_node, executor.submit( + self.syncNodeCount, static_node, pool))) + + for static_node, result in synced_nodes: + try: + result.result() + except StaticNodeError as exc: + self.log.warning("Couldn't sync node: %s", exc) + continue + except Exception: + self.log.exception("Couldn't sync node %s:", + nodeTuple(static_node)) + continue def getRequestHandler(self, poolworker, request): return StaticNodeRequestHandler(poolworker, request)