Skip to content

Commit aa9168a

Browse files
Warn when HTTP_PORT_1/2 are already in use (#3620)
We faced an issue on android bots were several bots on a host were using the same HTTP server for the test cases, which resulted in the wrong test case being served. this is mitigated when using the standard start up script (https://github.com/google/clusterfuzz/blob/530f8e342a45374f1afc063a17d76696a812517a/configs/test/bot/setup/android.bash#L33 ), which is not the case here. That start up script wouldn't work anyway because it is invoked once per bot in the android context. I originally thought about implementing the support for a port range (see below), but in the end I felt like it did not really had its place here. Instead, I'd like us to have at least a clue that something might be wrong, hence adding some logs. And I fixed the port issue in the scripts we are using instead. ``` def start(): """Initialize the HTTP server on the specified ports.""" http_host = 'localhost' def start_on_port(variable_name, default_port): http_port_range =[ int(x) for x in environment.get_value(variable_name, default_port).split('-')] for port in range(http_port_range[0], http_port_range[-1]+1): if not port_is_open(http_host, port): start_server_thread(http_host, port) return port return None start_on_port("HTTP_PORT_1", "8000 - 8020") start_on_port('HTTP_PORT_2', "8080 - 8100") ``` --------- Co-authored-by: Oliver Chang <[email protected]>
1 parent 6d8bcf8 commit aa9168a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/clusterfuzz/_internal/bot/webserver/http_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import socket
2020
import threading
2121

22+
from clusterfuzz._internal.metrics import logs
2223
from clusterfuzz._internal.system import environment
2324

2425

@@ -146,5 +147,13 @@ def start():
146147
http_port_2 = environment.get_value('HTTP_PORT_2', 8080)
147148
if not port_is_open(http_host, http_port_1):
148149
start_server_thread(http_host, http_port_1)
150+
else:
151+
logs.log_warn(
152+
f"HTTP_PORT_1 ({http_port_1}) already open, not starting server thread."
153+
)
149154
if not port_is_open(http_host, http_port_2):
150155
start_server_thread(http_host, http_port_2)
156+
else:
157+
logs.log_warn(
158+
f"HTTP_PORT_2 ({http_port_2}) already open, not starting server thread."
159+
)

0 commit comments

Comments
 (0)