This is an automated email from the ASF dual-hosted git repository.
yongzao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 9be854c0e70 Fix Process resource leak in system metrics collection
(#17212)
9be854c0e70 is described below
commit 9be854c0e7099f9527b89197ece0b7531a42cee9
Author: ZIHAN DAI <[email protected]>
AuthorDate: Mon Mar 23 16:01:51 2026 +1100
Fix Process resource leak in system metrics collection (#17212)
---
.../iotdb/metrics/metricsets/net/LinuxNetMetricManager.java | 13 ++++++++++++-
.../iotdb/metrics/metricsets/system/SystemMetrics.java | 11 ++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git
a/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java
b/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java
index 2c81bc0efc0..19cc1608a1e 100644
---
a/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java
+++
b/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java
@@ -218,8 +218,9 @@ public class LinuxNetMetricManager implements
INetMetricManager {
if (MetricLevel.higherOrEqual(MetricLevel.NORMAL,
METRIC_CONFIG.getMetricLevel())) {
// update socket num
+ Process process = null;
try {
- Process process = Runtime.getRuntime().exec(this.getConnectNumCmd);
+ process = Runtime.getRuntime().exec(this.getConnectNumCmd);
StringBuilder result = new StringBuilder();
try (BufferedReader input =
new BufferedReader(new
InputStreamReader(process.getInputStream()))) {
@@ -228,9 +229,19 @@ public class LinuxNetMetricManager implements
INetMetricManager {
result.append(line);
}
}
+ process.waitFor();
this.connectionNum = Integer.parseInt(result.toString().trim());
} catch (IOException e) {
LOGGER.error("Failed to get socket num", e);
+ } catch (InterruptedException e) {
+ LOGGER.error("Interrupted while waiting for socket num command", e);
+ Thread.currentThread().interrupt();
+ } catch (NumberFormatException e) {
+ LOGGER.error("Failed to parse socket num from command output: '{}'",
e.getMessage());
+ } finally {
+ if (process != null && process.isAlive()) {
+ process.destroyForcibly();
+ }
}
}
}
diff --git
a/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/system/SystemMetrics.java
b/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/system/SystemMetrics.java
index 1cacf2bf6f5..e14d8910791 100644
---
a/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/system/SystemMetrics.java
+++
b/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/system/SystemMetrics.java
@@ -217,8 +217,9 @@ public class SystemMetrics implements IMetricSet {
long time = System.currentTimeMillis();
if (time - lastUpdateTime > MetricConstant.UPDATE_INTERVAL) {
lastUpdateTime = time;
+ Process process = null;
try {
- Process process = runtime.exec(getSystemMemoryCommand);
+ process = runtime.exec(getSystemMemoryCommand);
StringBuilder result = new StringBuilder();
try (BufferedReader input =
new BufferedReader(new
InputStreamReader(process.getInputStream()))) {
@@ -227,6 +228,7 @@ public class SystemMetrics implements IMetricSet {
result.append(line).append("\n");
}
}
+ process.waitFor();
String[] lines = result.toString().trim().split("\n");
// if failed to get result
if (lines.length >= 2) {
@@ -240,6 +242,13 @@ public class SystemMetrics implements IMetricSet {
}
} catch (IOException e) {
logger.debug("Failed to get memory, because ", e);
+ } catch (InterruptedException e) {
+ logger.debug("Interrupted while waiting for memory command", e);
+ Thread.currentThread().interrupt();
+ } finally {
+ if (process != null && process.isAlive()) {
+ process.destroyForcibly();
+ }
}
}
}