davidzollo commented on code in PR #17005:
URL: 
https://github.com/apache/dolphinscheduler/pull/17005#discussion_r1963673912


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java:
##########
@@ -216,13 +216,30 @@ public void cancelApplication() throws 
InterruptedException {
             return;
         }
 
-        // soft kill
-        log.info("Begin to kill process process, pid is : {}", 
taskRequest.getProcessId());
-        process.destroy();
-        if (!process.waitFor(5, TimeUnit.SECONDS)) {
+        try {
+            // Try to kill process tree first
+            boolean killed = ProcessUtils.kill(taskRequest);
+            if (killed) {
+                log.info("Successfully killed process tree for task: {}, pid: 
{}",
+                        taskRequest.getTaskAppId(), 
taskRequest.getProcessId());
+                return;
+            }
+
+            // If killing process tree fails, try to destroy the process 
directly
+            log.info("Failed to kill process tree, trying to destroy process 
directly");
+            process.destroy();
+            if (!process.waitFor(5, TimeUnit.SECONDS)) {
+                log.info("Process did not exit after destroy, forcing 
termination");
+                process.destroyForcibly();
+            }
+            log.info("Successfully killed process tree for task: {}, pid: {}",
+                    taskRequest.getTaskAppId(), taskRequest.getProcessId());
+
+        } catch (Exception e) {
+            log.error("Error while killing process, pid: {}", 
taskRequest.getProcessId(), e);
+            // Try destroyForcibly as last resort
             process.destroyForcibly();

Review Comment:
   I have been removed these logic,thx



-- 
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]

Reply via email to