From 8627538928f64df8f5085efcd50c86b14861c984 Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Sun, 1 Nov 2026 21:50:18 +0100 Subject: [PATCH] [IT] Read the address column of lsof when checking port occupation EnvUtils.listPortOccupationUnix() parses the output of "lsof -iTCP -sTCP:LISTEN,TIME_WAIT -P -n" and took the local address from column 9. A line splits into 10 columns, though, and column 9 is the state, e.g. "(LISTEN)": java 1234 user 77u IPv6 0x1a2b 0t0 TCP 127.0.0.1:6667 (LISTEN) 0 1 2 3 4 5 6 7 8 9 So no line ever matched, and the method always returned an empty map on Linux and macOS. As a result: - searchAvailablePorts() handed out ports that another process was already listening on, and the node failed to start with "Could not create ServerSocket ... Address already in use"; - the PORT_OCCUPIED handling in AbstractEnv.handleProcessStatus() never found the node holding a port, so it never restarted it. Read the address from column 8. The Windows variant (netstat) was already correct. --- .../main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java index b69e86c12bd42..563938270051e 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java @@ -175,12 +175,15 @@ public static Map listPortOccupationWindows(final List p /** * List occupied port and the associated pid on Unix. * + *

A line of the lsof output splits into 10 columns, e.g. {@code java 1234 user 77u IPv6 0x1a2b + * 0t0 TCP 127.0.0.1:6667 (LISTEN)}. The address is in column 8 and the state in column 9. + * * @param ports ports to be checked * @return (occupiedPort, pid) pairs */ public static Map listPortOccupationUnix(final List ports) throws IOException { - return listPortOccupation(ports, "lsof -iTCP -sTCP:LISTEN,TIME_WAIT -P -n", 10, 9, 1); + return listPortOccupation(ports, "lsof -iTCP -sTCP:LISTEN,TIME_WAIT -P -n", 10, 8, 1); } private static Pair getClusterNodesNum(final int index) {