JackieTien97 opened a new pull request, #18883:
URL: https://github.com/apache/iotdb/pull/18883
## Description
On Windows, `sbin\windows\stop-datanode.bat` finds the DataNode process with:
```bat
for /f "tokens=5" %%a in ('netstat /ano ^| findstr :%dn_rpc_port% ') do (
taskkill /f /pid %%a
```
`findstr :6667` matches every netstat row that contains `:6667`, not only
the DataNode's listening socket. So the script also force-kills:
- clients connected to the DataNode, such as the CLI, Session/JDBC
applications, and other services, because their rows have `:6667` as the
foreign address;
- `TIME_WAIT` rows, whose PID is 0 (`taskkill` fails with an error);
- unrelated processes whose address or port merely contains the string, e.g.
a process listening on `55551` when `dn_rpc_port=5555`.
It also runs `taskkill` on the DataNode once per accepted connection, so
every call after the first prints `process not found`. Every PID it kills is
reported as `Close DataNode`.
### Fix
Only the listening socket on `dn_rpc_port` is selected now:
```bat
for /f "tokens=5" %%a in ('netstat /ano ^| findstr /c:":%dn_rpc_port% " ^|
findstr /c:":0 "') do (
```
- `":<port> "` includes the space that follows the address column, so the
port must match exactly. `55551` no longer matches `5555`, and neither do IPv6
address groups, which are followed by `:` or `]`.
- `":0 "` keeps only rows whose foreign port is 0, which is how netstat
shows listening sockets (`0.0.0.0:0`, `[::]:0`). Combined with the first
filter, the port can only be the local one, so connected clients and
`TIME_WAIT` rows are excluded.
- This is equivalent to filtering on `LISTENING`, as `stop-confignode.bat`
and `stop-datanode.sh` do. It does not depend on netstat's State column,
though, whose values come from the language-specific `netstat.exe.mui` and can
be translated on non-English Windows.
### Validation
Tested on Windows 11 (zh-CN) with JDK 21. The cluster was a real 1
ConfigNode + 1 DataNode from the `all-bin` distribution, with its
`stop-datanode.bat` replaced by this PR's version. Unless noted, an IoTDB CLI
session and a third-party TCP client were connected to the DataNode RPC port,
and a `TIME_WAIT` row was present.
| Scenario | master | This PR |
| --- | --- | --- |
| Default `127.0.0.1:6667` | Killed the DataNode, the CLI, and the TCP
client; `taskkill` on PID 0 failed; the DataNode PID was targeted 3 times |
Killed only the DataNode, once; the CLI, the TCP client, and the ConfigNode
kept running |
| `dn_rpc_port=5555` plus an unrelated listener on `55551` | Killed the
unrelated listener, the DataNode, the CLI, and the TCP client | Killed only the
DataNode |
| `dn_rpc_address=0.0.0.0`, CRLF `iotdb-system.properties` | Not run |
Killed only the DataNode |
| No DataNode running (clients still running, not connected) | Not run |
Killed nothing |
| `stop-standalone.bat` (no `TIME_WAIT` row) | Not run | Stopped the
ConfigNode and the DataNode; clients kept running |
The filter was also checked against crafted netstat rows. They covered IPv4
and IPv6 listeners, a translated State value, server- and client-side
`ESTABLISHED`, `TIME_WAIT`, `CLOSE_WAIT`, UDP, an IPv6 address containing
`:6667`, a connection to a remote `:6667`, and a `55551` listener. Only the
listening rows of the configured port are selected.
With a wildcard `dn_rpc_address`, Java listens on both `0.0.0.0:6667` and
`[::]:6667`. `taskkill` therefore runs twice for the same PID, and the second
call prints `process not found`. This is harmless and also happened before this
change. `stop-confignode.bat` behaves the same way.
<hr>
This PR has:
- [x] been self-reviewed.
- [x] added comments explaining the intent of non-obvious changes.
- [x] been tested in a test IoTDB cluster.
### Key changed files
`scripts/sbin/windows/stop-datanode.bat`
🤖 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]