From ef377dd8fe007bd581e67413f3eae46a0a13a43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=A0=E6=9F=B1?= Date: Fri, 20 May 2022 17:47:13 +0800 Subject: [PATCH 1/2] fix: client_listener will raise an KeyError error when received a client_stopped message from an unknown worker. --- locust/runners.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/locust/runners.py b/locust/runners.py index b1649860b8..fc63f9fe17 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -937,14 +937,15 @@ def client_listener(self): # if abs(time() - msg.data["time"]) > 5.0: # warnings.warn("The worker node's clock seem to be out of sync. For the statistics to be correct the different locust servers need to have synchronized clocks.") elif msg.type == "client_stopped": - client = self.clients[msg.node_id] - del self.clients[msg.node_id] - if self._users_dispatcher is not None: - self._users_dispatcher.remove_worker(client) - if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING: - # TODO: Test this situation - self.start(self.target_user_count, self.spawn_rate) - logger.info(f"Removing {msg.node_id} client from running clients") + if msg.node_id in self.clients: + client = self.clients[msg.node_id] + del self.clients[msg.node_id] + if self._users_dispatcher is not None: + self._users_dispatcher.remove_worker(client) + if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING: + # TODO: Test this situation + self.start(self.target_user_count, self.spawn_rate) + logger.info(f"Removing {msg.node_id} client from running clients") elif msg.type == "heartbeat": if msg.node_id in self.clients: c = self.clients[msg.node_id] From 5e6a3f839b22d4564a9986ff13cefdb199e7a7a5 Mon Sep 17 00:00:00 2001 From: jiazhu Date: Sun, 22 May 2022 23:50:07 +0800 Subject: [PATCH 2/2] Determine if the client is known, when received client stopped message and add logs --- locust/runners.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/locust/runners.py b/locust/runners.py index fc63f9fe17..abb6db4db9 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -937,15 +937,17 @@ def client_listener(self): # if abs(time() - msg.data["time"]) > 5.0: # warnings.warn("The worker node's clock seem to be out of sync. For the statistics to be correct the different locust servers need to have synchronized clocks.") elif msg.type == "client_stopped": - if msg.node_id in self.clients: - client = self.clients[msg.node_id] - del self.clients[msg.node_id] - if self._users_dispatcher is not None: - self._users_dispatcher.remove_worker(client) - if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING: - # TODO: Test this situation - self.start(self.target_user_count, self.spawn_rate) - logger.info(f"Removing {msg.node_id} client from running clients") + if msg.node_id not in self.clients: + logger.warning(f"Received {msg.type} message from an unknown client: {msg.node_id}.") + continue + client = self.clients[msg.node_id] + del self.clients[msg.node_id] + if self._users_dispatcher is not None: + self._users_dispatcher.remove_worker(client) + if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING: + # TODO: Test this situation + self.start(self.target_user_count, self.spawn_rate) + logger.info(f"Removing {msg.node_id} client from running clients") elif msg.type == "heartbeat": if msg.node_id in self.clients: c = self.clients[msg.node_id]