chrisdutz opened a new pull request, #19070:
URL: https://github.com/apache/iotdb/pull/19070

   ## Description
   
   ### Problem
   
   On Linux and macOS, the IT framework never detects ports that are already in 
use. `EnvUtils.searchAvailablePorts()` then hands out ports another process 
listens on, and a node fails to start:
   
   ```
   StartupException: Failed to start [Config Node service], because [IoTDB: 
failed to start Config Node service,
   because Could not create ServerSocket on address /127.0.0.1:16490.]
   java.net.BindException: Address already in use
   ```
   
   The test then fails in `setUp` with "After 30 times retry, the cluster 
status check failed: ... Empty configNode set". On my machine this hit two ITs 
in one SimpleIT/TableSimpleIT run, because another local process was listening 
on 127.0.0.1:16490.
   
   ### Cause
   
   `listPortOccupationUnix()` parses `lsof -iTCP -sTCP:LISTEN,TIME_WAIT -P -n` 
and takes the local address from column 9. A line splits into 10 columns, and 
column 9 is the state:
   
   ```
   java 1234 user 77u IPv6 0x1a2b 0t0 TCP 127.0.0.1:6667 (LISTEN)
   0    1    2    3   4    5      6   7   8              9
   ```
   
   `"(LISTEN)".endsWith(":" + port)` is never true, so the method always 
returns an empty map. This also disables the `PORT_OCCUPIED` handling in 
`AbstractEnv.handleProcessStatus()`, which uses the same method to find and 
restart a node that holds a port.
   
   ### Fix
   
   Read the address from column 8. The Windows variant (`netstat -aon -p tcp`, 
address in column 1) was already correct. A Javadoc line shows the column 
layout.
   
   ### Verification
   
   - The layout is the same on both platforms:
     - macOS 27, lsof 4.91: `... TCP 127.0.0.1:16490 (LISTEN)`, 10 columns.
     - Ubuntu 26.04, lsof 4.99.4: `... TCP 127.0.0.1:6667 (LISTEN)` and `... 
TCP [::1]:6668 (LISTEN)`, 10 columns, address in column 8.
   - Called `EnvUtils.listPortOccupationUnix(...)` directly on macOS, on master 
and with this change:
   
     | Port | Before | After |
     |---|---|---|
     | 16490 (held by another process) | `{}` | `{16490=<pid>}` |
     | 15292 (held by another process) | `{}` | `{15292=<pid>}` |
     | 16491 (free) | `{}` | `{}` |
   
   - `spotless:check` passes for `integration-test`.
   - IT runs with this change, on macOS: `EdgeIT` (7 tests) and 
`IoTDBWithoutNullAllFilterIT` (SimpleIT, 11 tests, 5 skipped) pass.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) 
in this PR
   
   - 
`integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java`
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to