ruanwenjun commented on code in PR #17437:
URL: 
https://github.com/apache/dolphinscheduler/pull/17437#discussion_r2318766846


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -115,13 +115,23 @@ public static boolean kill(@NonNull TaskExecutionContext 
request) {
             // Get all child processes
             String pids = getPidsStr(processId);
             String[] pidArray = PID_PATTERN.split(pids);
-            if (pidArray.length == 0) {
+            if (StringUtils.isBlank(pids) || pidArray.length == 0) {
                 log.warn("No valid PIDs found for process: {}", processId);
                 return true;
             }
 
             // Convert PID string to list of integers
-            List<Integer> pidList = 
Arrays.stream(pidArray).map(Integer::parseInt).collect(Collectors.toList());
+            List<Integer> pidList = 
Arrays.stream(pidArray).filter(StringUtils::isNotBlank)
+                    .map(s -> {
+                        try {
+                            return Integer.parseInt(s.trim());
+                        } catch (NumberFormatException e) {
+                            log.warn("Invalid PID string ignored: {}", s);
+                            return null;

Review Comment:
   Throw exception here, catch the exception will hide the bug.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -115,13 +115,23 @@ public static boolean kill(@NonNull TaskExecutionContext 
request) {
             // Get all child processes
             String pids = getPidsStr(processId);
             String[] pidArray = PID_PATTERN.split(pids);
-            if (pidArray.length == 0) {
+            if (StringUtils.isBlank(pids) || pidArray.length == 0) {
                 log.warn("No valid PIDs found for process: {}", processId);
                 return true;
             }
 
             // Convert PID string to list of integers
-            List<Integer> pidList = 
Arrays.stream(pidArray).map(Integer::parseInt).collect(Collectors.toList());
+            List<Integer> pidList = 
Arrays.stream(pidArray).filter(StringUtils::isNotBlank)
+                    .map(s -> {
+                        try {
+                            return Integer.parseInt(s.trim());
+                        } catch (NumberFormatException e) {
+                            log.warn("Invalid PID string ignored: {}", s);
+                            return null;
+                        }
+                    })
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList());

Review Comment:
   It's better to change `getPidsStr` return a validate pid list, rather than 
parse the pid in up layer.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java:
##########
@@ -190,13 +191,13 @@ public TaskResponse run(IShellInterceptorBuilder 
iShellInterceptorBuilder,
             result.setExitStatusCode(this.process.exitValue());
 
         } else {
-            log.error("process has failure, the task timeout configuration 
value is:{}, ready to kill ...",
-                    taskRequest.getTaskTimeout());
+            log.error("process has failure due to timeout kill, timeout value 
is:{}, timeoutStrategy is:{}",
+                    taskRequest.getTaskTimeout(), 
taskRequest.getTaskTimeoutStrategy());
             result.setExitStatusCode(EXIT_CODE_FAILURE);
-            cancelApplication();
         }
         int exitCode = this.process.exitValue();
-        String exitLogMessage = EXIT_CODE_KILL == exitCode ? "process has 
killed." : "process has exited.";
+        String exitLogMessage = (EXIT_CODE_KILL == exitCode || 
EXIT_CODE_HARD_KILL == exitCode) ? "process has killed."
+                : "process has exited.";

Review Comment:
   It's better to check from status in `taskExecutionContext` rather then check 
from the exit code, we don't care about the exit, only kill from ds then we 
think it's kill.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -115,13 +115,23 @@ public static boolean kill(@NonNull TaskExecutionContext 
request) {
             // Get all child processes
             String pids = getPidsStr(processId);
             String[] pidArray = PID_PATTERN.split(pids);
-            if (pidArray.length == 0) {
+            if (StringUtils.isBlank(pids) || pidArray.length == 0) {

Review Comment:
   if`StringUtils.isEmpty(pids)` then we don't need to execute line 117.



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