From 3209226fc17d730fcb10ea5dbda7e26eab183742 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Thu, 9 Mar 2023 09:03:42 +0100 Subject: [PATCH] Respect timeout when not accepting requests So far the timeout was only in effect when any of the requests was accepted by the launcher. When there are a lot of other requests (e.g. to be declined) we might exceed the timout in some cases. Change-Id: Iaed8302c94e12467834fadee25a80198db5e629d --- nodepool/launcher.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nodepool/launcher.py b/nodepool/launcher.py index b0d89241a..5201bf807 100644 --- a/nodepool/launcher.py +++ b/nodepool/launcher.py @@ -148,6 +148,14 @@ class PoolWorker(threading.Thread, stats.StatsReporter): if not self.running: return True + # if we exceeded the timeout stop iterating here + elapsed = time.monotonic() - start + if elapsed > timeout: + self.log.debug("Early exit from handler assignment on timeout " + "after %s/%s requests in %s", + req_count + 1, len(requests), elapsed) + return False + req = self.zk.getNodeRequest(req.id) if not req: continue @@ -279,13 +287,6 @@ class PoolWorker(threading.Thread, stats.StatsReporter): self.paused_handlers.add(rh) self.request_handlers.append(rh) - # if we exceeded the timeout stop iterating here - elapsed = time.monotonic() - start - if elapsed > timeout: - self.log.debug("Early exit from handler assignment on timeout " - "after %s/%s requests in %s", - req_count + 1, len(requests), elapsed) - return False elapsed = time.monotonic() - start self.log.debug("Finished handler assignment %s requests in %s", len(requests), elapsed)