You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2022/11/27 06:29:56 UTC

[dolphinscheduler] branch 3.1.2-prepare updated: [Bug-12994] [Worker] Fix kill process does not take effect (#12995)

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

kerwin pushed a commit to branch 3.1.2-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/3.1.2-prepare by this push:
     new f27db04a8b [Bug-12994] [Worker] Fix kill process does not take effect (#12995)
f27db04a8b is described below

commit f27db04a8b0e535bddab3472487b86a804a17b81
Author: Kerwin <37...@users.noreply.github.com>
AuthorDate: Sun Nov 27 14:27:48 2022 +0800

    [Bug-12994] [Worker] Fix kill process does not take effect (#12995)
---
 .../plugin/task/api/AbstractCommandExecutor.java   | 25 ++++++++++------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
index ff39064504..6ae62fe1ea 100644
--- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
+++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
@@ -17,6 +17,7 @@
 
 package org.apache.dolphinscheduler.plugin.task.api;
 
+import static org.apache.dolphinscheduler.plugin.task.api.ProcessUtils.getPidsStr;
 import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_FAILURE;
 import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL;
 
@@ -235,10 +236,11 @@ public abstract class AbstractCommandExecutor {
             ProcessUtils.kill(taskRequest);
             result.setExitStatusCode(EXIT_CODE_FAILURE);
         }
-
-        logger.info(
-                "process has exited, execute path:{}, processId:{} ,exitStatusCode:{} ,processWaitForStatus:{} ,processExitValue:{}",
-                taskRequest.getExecutePath(), processId, result.getExitStatusCode(), status, process.exitValue());
+        int exitCode = process.exitValue();
+        String exitLogMessage = EXIT_CODE_KILL == exitCode ? "process has killed." : "process has exited.";
+        logger.info(exitLogMessage
+                + " execute path:{}, processId:{} ,exitStatusCode:{} ,processWaitForStatus:{} ,processExitValue:{}",
+                taskRequest.getExecutePath(), processId, result.getExitStatusCode(), status, exitCode);
         return result;
 
     }
@@ -265,16 +267,11 @@ public abstract class AbstractCommandExecutor {
         logger.info("cancel process: {}", processId);
 
         // kill , waiting for completion
-        boolean killed = softKill(processId);
+        boolean alive = softKill(processId);
 
-        if (!killed) {
+        if (alive) {
             // hard kill
             hardKill(processId);
-
-            // destory
-            process.destroy();
-
-            process = null;
         }
     }
 
@@ -310,12 +307,12 @@ public abstract class AbstractCommandExecutor {
     private void hardKill(int processId) {
         if (processId != 0 && process.isAlive()) {
             try {
-                String cmd = String.format("kill -9 %d", processId);
+                String cmd = String.format("kill -9 %s", getPidsStr(processId));
                 cmd = OSUtils.getSudoCmd(taskRequest.getTenantCode(), cmd);
                 logger.info("hard kill task:{}, process id:{}, cmd:{}", taskRequest.getTaskAppId(), processId, cmd);
 
-                Runtime.getRuntime().exec(cmd);
-            } catch (IOException e) {
+                OSUtils.exeCmd(cmd);
+            } catch (Exception e) {
                 logger.error("kill attempt failed ", e);
             }
         }