From e441ce2fd9fba2078d8913bf99df1da1fbd010d2 Mon Sep 17 00:00:00 2001 From: Piotr Smaron Date: Mon, 25 May 2026 14:49:47 +0200 Subject: [PATCH] test/nodetool: bind JMX to per-module loopback IP The Cassandra nodetool fixture picked a random JMX port on 127.0.0.1, which can collide with unrelated listeners and has a TOCTOU race between port selection and bind. Bind JMX to the per-module loopback IP with the standard port 7199 instead. Set java.rmi.server.hostname so the RMI endpoint stays on the same leased address. --- test/nodetool/conftest.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/nodetool/conftest.py b/test/nodetool/conftest.py index 5c75bc5714..4472719c2e 100644 --- a/test/nodetool/conftest.py +++ b/test/nodetool/conftest.py @@ -134,11 +134,9 @@ def jmx(request, rest_api_mock_server): response=[])] set_expected_requests(rest_api_mock_server, expected_requests) - # Our nodetool launcher script ignores the host param, so this has to be 127.0.0.1, matching the internal default. - jmx_ip = "127.0.0.1" - jmx_port = random.randint(10000, 65535) - while jmx_port == api_port: - jmx_port = random.randint(10000, 65535) + # Bind JMX to the same per-module loopback IP as the REST mock. + jmx_ip = ip + jmx_port = 7199 jmx_process = subprocess.Popen( [ @@ -147,6 +145,7 @@ def jmx(request, rest_api_mock_server): "-p", str(api_port), "-ja", jmx_ip, "-jp", str(jmx_port), + f"-Djava.rmi.server.hostname={jmx_ip}", ], cwd=workdir, text=True)