From 3721288ce7369b3933509f24cec41c4bfcd4461c Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Tue, 7 Jul 2020 10:21:42 +0200 Subject: [PATCH 1/2] Improve logging when locust master port is busy. --- locust/runners.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/locust/runners.py b/locust/runners.py index d23d2ff7c8..8b22bbfe25 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -2,6 +2,7 @@ import logging import random import socket +import sys import traceback import warnings from uuid import uuid4 @@ -399,7 +400,16 @@ def missing(self): return self.get_by_state(STATE_MISSING) self.clients = WorkerNodesDict() - self.server = rpc.Server(master_bind_host, master_bind_port) + try: + self.server = rpc.Server(master_bind_host, master_bind_port) + except RPCError as e: + if e.args[0] == "Socket bind failure: Address already in use": + port_string = master_bind_host + ":" + master_bind_port if master_bind_host != "*" else master_bind_port + logger.error(f"The Locust master port ({port_string}) was busy. Close any applications using that port - perhaps an old instance of Locust is still running? ({e.args[0]})") + sys.exit(1) + else: + raise + self.greenlet.spawn(self.heartbeat_worker).link_exception(greenlet_exception_handler) self.greenlet.spawn(self.client_listener).link_exception(greenlet_exception_handler) From 8968ee6e2faa03f5c9af6d4e109fa7d52a147add Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Tue, 7 Jul 2020 10:36:34 +0200 Subject: [PATCH 2/2] further clarify log message --- locust/runners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locust/runners.py b/locust/runners.py index 8b22bbfe25..bc99075f5b 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -405,7 +405,7 @@ def missing(self): except RPCError as e: if e.args[0] == "Socket bind failure: Address already in use": port_string = master_bind_host + ":" + master_bind_port if master_bind_host != "*" else master_bind_port - logger.error(f"The Locust master port ({port_string}) was busy. Close any applications using that port - perhaps an old instance of Locust is still running? ({e.args[0]})") + logger.error(f"The Locust master port ({port_string}) was busy. Close any applications using that port - perhaps an old instance of Locust master is still running? ({e.args[0]})") sys.exit(1) else: raise