This is an automated email from the ASF dual-hosted git repository.

zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 5e179136d9 [Fix-16650] Memory leaks in KubernetesApplicationManager 
(#16652)
5e179136d9 is described below

commit 5e179136d9a9f4f26de93fbd2e28f9b237c3089b
Author: Terry Tao <[email protected]>
AuthorDate: Thu Sep 26 20:27:50 2024 +0800

    [Fix-16650] Memory leaks in KubernetesApplicationManager (#16652)
---
 .../plugin/task/api/k8s/impl/K8sTaskExecutor.java             |  2 ++
 .../dolphinscheduler/plugin/task/api/utils/ProcessUtils.java  |  6 ++++++
 .../plugin/task/api/utils/ProcessUtilsTest.java               | 11 +++++++++++
 3 files changed, 19 insertions(+)

diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java
index e8ca6370f0..f48169c5e1 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java
@@ -319,6 +319,8 @@ public class K8sTaskExecutor extends 
AbstractK8sTaskExecutor {
             Thread.currentThread().interrupt();
             result.setExitStatusCode(EXIT_CODE_FAILURE);
             throw e;
+        } finally {
+            ProcessUtils.removeK8sClientCache(taskRequest.getTaskAppId());
         }
         return result;
     }
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java
index 555c69bc5c..27105184b6 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java
@@ -243,4 +243,10 @@ public final class ProcessUtils {
                 .getPodLogWatcher(
                         new 
KubernetesApplicationManagerContext(k8sTaskExecutionContext, taskAppId, 
containerName));
     }
+
+    public static void removeK8sClientCache(String taskAppId) {
+        KubernetesApplicationManager applicationManager =
+                (KubernetesApplicationManager) 
applicationManagerMap.get(ResourceManagerType.KUBERNETES);
+        applicationManager.removeCache(taskAppId);
+    }
 }
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java
index 14caf470d7..53bd77dc20 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java
@@ -84,4 +84,15 @@ public class ProcessUtilsTest {
         Assertions.assertEquals(exceptPidsStr3, actualPidsStr3);
     }
 
+    @Test
+    public void tetRemoveK8sClientCache() {
+        Assertions.assertDoesNotThrow(() -> {
+            ProcessUtils.removeK8sClientCache("a");
+        });
+
+        Assertions.assertThrows(Exception.class, () -> {
+            ProcessUtils.removeK8sClientCache(null);
+        });
+    }
+
 }

Reply via email to