JackieTien97 opened a new pull request, #19120:
URL: https://github.com/apache/iotdb/pull/19120
## Summary
On `dev/1.3`, the IT framework never detects an occupied port.
`EnvUtils.checkPortsAvailable()` passed a shell pipeline (`lsof -iTCP
-sTCP:LISTEN,TIME_WAIT -P -n | awk '{print $9}' | grep -E ...` on Unix,
`netstat -aon -p tcp | findStr ...` on Windows) to `Runtime.exec(String)`,
which does not use a shell. lsof received `|`, `awk`, ... as file names and
exited with 1, which the method treats as "available". `searchAvailablePorts()`
therefore accepted every port range even when one of its ports was in use, and
a node could then fail with `BindException`.
This PR ports the master implementation, which runs lsof / netstat without a
shell and parses the output in Java:
- the `EnvUtils` part of #15794 (source commit
`88abd3e3097f9f1c16c51945c0ab0cf74307263b`): `checkPortsAvailable()` delegates
to `listPortOccupation(...)`;
- #19070 (source commit `2fd7d838cbab3bd8645681b8020c5597e340378d`): read
the lsof address from column 8 instead of the state column 9.
Target base: `dev/1.3` at `c0811e54d01c1f4480d10506930c44d06cfb12e6`. After
this change, the port-check block of `EnvUtils` (`checkPortsAvailable` through
`listPortOccupationUnix`) is identical to master at `2fd7d838cb`.
## Compatibility adaptations
- Explicit `java.io` imports instead of `java.io.*`, because the Checkstyle
`AvoidStarImport` rule is error level.
- The lsof state filter stays `LISTEN,TIME_WAIT`, as already on `dev/1.3`
(#17618) and on master (#17551).
- `getSearchAvailablePortCmd`, `getWindowsSearchPortCmd` and
`getUnixSearchPortCmd` become unused and are removed, as master did in #17551.
Only the `EnvUtils` part of #15794 is included. Its cluster-restart handling
(`AbstractEnv`, `AbstractNodeWrapper`) and server-side changes are not part of
this backport; on `dev/1.3` only `checkPortsAvailable()` uses the `(port, pid)`
map returned by `listPortOccupation(...)`.
## Validation
Local validation with JDK 17.0.5 and Maven 3.9.9:
- `mvn clean package -DskipTests -pl integration-test -am -P
with-integration-tests`: build success, Spotless clean, 0 Checkstyle violations.
- Before the change (macOS): ranges containing a port held by `python3 -m
http.server`, or ports held by another local application, were all reported as
available; lsof printed `status error on |: No such file or directory` and
exited with 1.
- After the change (macOS, compiled `EnvUtils`): occupied ranges are
reported with the owning pid and `checkPortsAvailable()` returns false (IPv4
loopback, wildcard, a listener in the same JVM, the last port of the range).
Free ranges and a port just past the range are reported as free, and
`searchAvailablePorts()` returns a free range.
- Linux (`ubuntu:24.04` container, lsof 4.95.0 as on `ubuntu-latest`):
LISTEN lines have 10 columns with the address at index 8 and the pid at index
1, also for a multi-threaded process. IPv4 loopback, IPv4 wildcard and IPv6
loopback listeners are detected; the old index 9 matches nothing.
- `IoTDBSimpleQueryIT` (34 tests, a fresh cluster per test) and
`IoTDBFlushQueryIT` (7 tests) with `with-integration-tests` (SimpleIT): 0
failures/errors; the 3 skipped tests are `@Ignore`d in source.
- The Windows path (`netstat -aon -p tcp`) could not be run locally. It is
the same code master runs, and the Windows job of `Cluster IT - 1C1D` covers it
on this PR.
🤖 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]