You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "njnu-seafish (via GitHub)" <gi...@apache.org> on 2025/07/03 13:00:14 UTC

[PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

njnu-seafish opened a new pull request, #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320

   <!--Thanks very much for contributing to Apache DolphinScheduler, we are happy that you want to help us improve DolphinScheduler! -->
   
   ## Purpose of the pull request
   
   close https://github.com/apache/dolphinscheduler/issues/17316
   
   ## Brief change log
   
   after kill the process, and check process status
   
   ## Verify this pull request
   
   <!--*(Please pick either of the following options)*-->
   
   This pull request is code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   <!--*(example:)*
   - *Added dolphinscheduler-dao tests for end-to-end.*
   - *Added CronUtilsTest to verify the change.*
   - *Manually verified the change by testing locally.* -->
   
   (or)
   
   ## Pull Request Notice
   [Pull Request Notice](https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
   
   If your pull request contains incompatible change, you should also add it to `docs/docs/en/guide/upgrade/incompatible.md`
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3060424079

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [29.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047204972

   UT also failed. Please check it. @njnu-seafish 


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3048786283

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [36.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3087012684

   > ## [![Quality Gate Passed](https://camo.githubusercontent.com/f7c890f34e0efe8252e17e9afd5a85aa22fc9c81b42a0ec3d4821af9f55f250d/68747470733a2f2f736f6e6172736f757263652e6769746875622e696f2f736f6e6172636c6f75642d6769746875622d7374617469632d7265736f75726365732f76322f636865636b732f5175616c6974794761746542616467652f71672d7061737365642d323070782e706e67)](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate passed**
   > Issues ![](https://camo.githubusercontent.com/187ba88c264795e888bdd18141ef29390601e5110d4e9c8cc48f2f8afc183ba0/68747470733a2f2f736f6e6172736f757263652e6769746875622e696f2f736f6e6172636c6f75642d6769746875622d7374617469632d7265736f75726365732f76322f636f6d6d6f6e2f7061737365642d313670782e706e67) [2 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) ![](https://camo.githubusercontent.com/86e5c40907bf9e8933fe6bcf185f7076622a76a3bef4b6d2b5fd583959409aef/68747470733a2f2f736f6e6172736f757263652e6769746875622e696f2f736f6e6172636c6f75642d6769746875622d7374617469632d7265736f75726365732f76322f636f6d6d6f6e2f61636365707465642d313670782e706e67) [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=ACCEPTED)
   > 
   > Measures ![](https://camo.githubusercontent.com/187ba88c264795e888bdd18141ef29390601e5110d4e9c8cc48f2f8afc183ba0/68747470733a2f2f736f6e6172736f757263652e6769746875622e696f2f736f6e6172636c6f75642d6769746875622d7374617469632d7265736f75726365732f76322f636f6d6d6f6e2f7061737365642d313670782e706e67) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) ![](https://camo.githubusercontent.com/187ba88c264795e888bdd18141ef29390601e5110d4e9c8cc48f2f8afc183ba0/68747470733a2f2f736f6e6172736f757263652e6769746875622e696f2f736f6e6172636c6f75642d6769746875622d7374617469632d7265736f75726365732f76322f636f6d6d6f6e2f7061737365642d313670782e706e67) [91.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) ![](https://camo.githubusercontent.com/187ba88c264795e888bdd18141ef29390601e5110d4e9c8cc48f2f8afc183
 ba0/68747470733a2f2f736f6e6172736f757263652e6769746875622e696f2f736f6e6172636c6f75642d6769746875622d7374617469632d7265736f75726365732f76322f636f6d6d6f6e2f7061737365642d313670782e706e67) [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_duplicated_lines_density&view=list)
   > 
   > [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   I will remove the "throws Exception" in the test  


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047203700

   `Helm-Doc` check failed. I don't know why. PTAL @Gallardot 


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3048783355

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [36.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2191368103


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -134,6 +134,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."datasource.encryption.enable" | bool | `false` | datasource encryption enable |
 | conf.common."datasource.encryption.salt" | string | `"!@#$%^&*"` | datasource encryption salt |
 | conf.common."development.state" | bool | `false` | development state |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the process status after termination (in seconds) |

Review Comment:
   ```suggestion
   | conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |
   ```



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/resources/docker/file-manage/common.properties:
##########
@@ -99,6 +99,9 @@ sudo.enable=true
 # development state
 development.state=false
 
+# The delay before checking the process status after termination (in seconds)

Review Comment:
   ```suggestion
   # The delay before checking the shell process status after termination (in seconds)
   ```



##########
deploy/kubernetes/dolphinscheduler/values.yaml:
##########
@@ -345,6 +345,9 @@ conf:
     # -- development state
     development.state: false
 
+    # -- The delay before checking the process status after termination (in seconds)

Review Comment:
   ```suggestion
       # -- The delay before checking the shell process status after termination (in seconds)
   ```



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3060429990

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [29.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3071647251

   > > ## Pull Request Overview
   > > This PR adds a configurable timeout for waiting on shell process termination and enhances the kill logic to poll process status after sending kill signals. It also updates various resource configurations and bumps the Kubernetes Helm chart version.
   > > 
   > > * Introduce `shell.kill.wait.timeout` property in common configs and add `SHELL_KILL_WAIT_TIMEOUT` constant
   > > * Refactor `ProcessUtils.kill` to parse PIDs into a list, send signals, and poll until processes exit
   > > * Update E2E/test properties, document new config in Helm values and README, and bump chart version
   > > 
   > > ### Reviewed Changes
   > > Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
   > > Show a summary per file
   > > File	Description
   > > dolphinscheduler-task-plugin/.../common.properties	Add `shell.kill.wait.timeout` property
   > > ProcessUtils.java	Parse PIDs into `List<Integer>`, implement polling with timeout, add `isProcessAlive`
   > > dolphinscheduler-e2e/.../common.properties	Add timeout property and fix `appId.collect` syntax
   > > dolphinscheduler-common/.../common.properties	Add `shell.kill.wait.timeout` to test and main resources
   > > Constants.java	Add `SHELL_KILL_WAIT_TIMEOUT` constant
   > > values.yaml	Add `shell.kill.wait.timeout` under `conf`
   > > README.md	Document `shell.kill.wait.timeout` in chart config
   > > Chart.yaml	Bump `version` and `appVersion` to 3.1.1
   > > Comments suppressed due to low confidence (4)
   > > **dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java:75**
   > > 
   > > * [nitpick] The Javadoc for this constant is minimal. Consider expanding it to explain that this property defines the wait timeout in seconds before using SIGKILL.
   > > 
   > > ```
   > >     public static final String SHELL_KILL_WAIT_TIMEOUT = "shell.kill.wait.timeout";
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > **dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:54**
   > > 
   > > * It looks like `List` and `ArrayList` are used later in this class but not imported here. Please add `import java.util.List;` and `import java.util.ArrayList;` to avoid compile errors.
   > > 
   > > ```
   > > import java.util.stream.Collectors;
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > **dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:168**
   > > 
   > > * [nitpick] Mutating the original `pidList` inside this method can lead to side effects if the list is reused elsewhere. Consider making a defensive copy of the list before polling/removal.
   > > 
   > > ```
   > >     private static boolean sendKillSignal(String signal, List<Integer> pidList, String tenantCode) {
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > **dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:188**
   > > 
   > > * [nitpick] The multiplication here assumes `SLEEP_TIME_MILLIS` maps directly to milliseconds. It might be clearer to calculate `timeoutMillis = TimeUnit.SECONDS.toMillis(SHELL_KILL_WAIT_TIMEOUT)` or document the relationship explicitly.
   > > 
   > > ```
   > >             long timeoutMillis = SLEEP_TIME_MILLIS * SHELL_KILL_WAIT_TIMEOUT;
   > > ```
   > 
   > Please take care about the comment from copilot.
   
   Good,I add new function “getAlivePidList“ to avoid side effects


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3086639254

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [91.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3086640061

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [91.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2193933468


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   If the process doesn't exit, there seems to be no point in checking here



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047326244

   Please retry analysis of this Pull-Request directly on SonarQube Cloud


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2193823938


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   > I think it's better used for waiting the soft kill result. If it timeout then hard kill. This seems make little sense if only wait the process exit. If it doesn't exit, then you should not return.
   
   
   在实际开发和运维中,不要一上来就用 SIGKILL,这会剥夺进程清理资源的机会。推荐的做法是:
   先发 SIGINT,等待一定时间(比如 5~10 秒),检查进程状态
   如果未退出,再发送SIGTERM,等待一定时间(比如 5~10 秒),检查进程状态
   如果未退出,再发 SIGKILL。
   一个关键点:即使 SIGINT成功返回了,进程也可能还在运行,所以必须加上检查逻辑(check logic),确认进程是否真的退出



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3072746825

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [11.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2208988409


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java:
##########
@@ -132,7 +132,7 @@ void testKillProcessSuccessWithSigInt() throws Exception {
         boolean result = ProcessUtils.kill(taskRequest);
 
         // Assert
-        Assertions.assertTrue(result);
+        Assertions.assertFalse(result);

Review Comment:
   https://github.com/apache/dolphinscheduler/actions/runs/16282257223/job/45974113068  
   
   I also find it quite strange that this test case sometimes passes and sometimes fails. It seems to be related to the machine environment.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2209080234


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -100,29 +114,35 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
 
             // Get all child processes
             String pids = getPidsStr(processId);
-            String[] pidArray = pids.split("\\s+");
+            String[] pidArray = PID_PATTERN.split(pids);
             if (pidArray.length == 0) {
                 log.warn("No valid PIDs found for process: {}", processId);
                 return true;
             }
 
+            // Convert PID string to list of integers
+            List<Integer> pidList = new ArrayList<>();

Review Comment:
   Good Idea



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2207575758


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java:
##########
@@ -132,7 +132,7 @@ void testKillProcessSuccessWithSigInt() throws Exception {
         boolean result = ProcessUtils.kill(taskRequest);
 
         // Assert
-        Assertions.assertTrue(result);
+        Assertions.assertFalse(result);

Review Comment:
   Why change the assertion? Please fix the test case.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2189534804


##########
dolphinscheduler-common/src/main/resources/common.properties:
##########
@@ -104,4 +107,4 @@ shell.env_source_list=
 shell.interceptor.type=bash
 
 # Whether to enable remote logging
-remote.logging.enable=false
+remote.logging.enable=false

Review Comment:
   Please add blank lines at the end of each line.



##########
dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/resources/docker/file-manage/common.properties:
##########
@@ -111,4 +114,4 @@ ml.mlflow.preset_repository=https://github.com/apache/dolphinscheduler-mlflow
 ml.mlflow.preset_repository_version="main"
 
 # way to collect applicationId: log(original regex match), aop
-appId.collect: log
+appId.collect=log

Review Comment:
   Same here.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -244,11 +291,12 @@ public static void cancelApplication(TaskExecutionContext taskExecutionContext)
                     taskExecutionContext.setAppIds(String.join(TaskConstants.COMMA, appIds));
                 }
                 if (CollectionUtils.isEmpty(appIds)) {
-                    log.info("The appId is empty");
+                    log.info("The appId is empty, so there is no need to kill yarn application.");

Review Comment:
   ```suggestion
                       log.info("The appId is empty");
   ```
   
   We don't need this since not all shell task are yarn type.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +155,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
+            log.info("Kill command: {}, trying to terminate process", killCmd);

Review Comment:
   ```suggestion
   ```
   
   We don't need this log since we already log it in L162.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +155,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
+            log.info("Kill command: {}, trying to terminate process", killCmd);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);
+
+            // 3. Check if the processes are still running
+            String[] pidArray = PID_PATTERN.split(pids);
+            for (String pid : pidArray) {
+                // Check if each PID is still alive
+                if (isProcessAlive(Integer.parseInt(pid))) {
+                    log.info("Kill command: {}, kill failed, the process: {} is still running", killCmd, pid);
+                    // Return false if any process is still alive
+                    return false;
+                }
+            }
+            log.info("Kill command: {}, kill succeeded", killCmd);
+            // All processes have been successfully terminated
             return true;
         } catch (Exception e) {
             log.error("Error sending {} to process: {}", signal, pids, e);
             return false;
         }
     }
 
+    /**
+     * Check if a process with the specified PID is alive.
+     *
+     * @param pid the process ID to check
+     * @return true if the process exists and is running, false otherwise
+     */
+    private static boolean isProcessAlive(int pid) {
+        try {
+            // Use kill -0 to check if the process exists; it does not actually send a signal
+            String checkCmd = String.format("kill -0 %d", pid);
+            OSUtils.exeCmd(checkCmd);

Review Comment:
   Using `OSUtils.getSudoCmd` to get `killCmd`



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +155,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
+            log.info("Kill command: {}, trying to terminate process", killCmd);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);
+
+            // 3. Check if the processes are still running
+            String[] pidArray = PID_PATTERN.split(pids);
+            for (String pid : pidArray) {
+                // Check if each PID is still alive
+                if (isProcessAlive(Integer.parseInt(pid))) {
+                    log.info("Kill command: {}, kill failed, the process: {} is still running", killCmd, pid);
+                    // Return false if any process is still alive
+                    return false;
+                }
+            }
+            log.info("Kill command: {}, kill succeeded", killCmd);

Review Comment:
   ```suggestion
               log.debug("Kill command: {}, kill succeeded", killCmd);
   ```



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3072746332

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [11.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3087466103

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [91.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2203761645


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -100,29 +113,39 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
 
             // Get all child processes
             String pids = getPidsStr(processId);
-            String[] pidArray = pids.split("\\s+");
+            String[] pidArray = PID_PATTERN.split(pids);
             if (pidArray.length == 0) {
                 log.warn("No valid PIDs found for process: {}", processId);
                 return true;
             }
 
+            // Convert PID string to list of integers
+            List<Integer> pidList = new ArrayList<>();
+            for (String pidStr : pidArray) {
+                try {
+                    pidList.add(Integer.parseInt(pidStr));
+                } catch (NumberFormatException e) {
+                    log.warn("Invalid PID: {}", pidStr);

Review Comment:
   return false?



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2189027875


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -56,6 +56,9 @@
 @Slf4j
 public final class ProcessUtils {
 
+    // Wait 5 seconds to check process status
+    private static final int CHECK_PROCESS_WAITING_MILLIS = 5000;

Review Comment:
   Well,Your suggestion is great, I'll incorporate it into the code.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2191328097


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +155,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);
+
+            // 3. Check if the processes are still running
+            String[] pidArray = PID_PATTERN.split(pids);
+            for (String pid : pidArray) {
+                // Check if each PID is still alive
+                if (isProcessAlive(Integer.parseInt(pid), tenantCode)) {
+                    log.info("Kill command: {}, kill failed, the process: {} is still running", killCmd, pid);
+                    // Return false if any process is still alive
+                    return false;
+                }
+            }
+            log.debug("Kill command: {}, kill succeeded", killCmd);
+            // All processes have been successfully terminated
             return true;
         } catch (Exception e) {
             log.error("Error sending {} to process: {}", signal, pids, e);
             return false;
         }
     }
 
+    /**
+     * Check if a process with the specified PID is alive.
+     *
+     * @param pid the process ID to check
+     * @return true if the process exists and is running, false otherwise
+     */
+    private static boolean isProcessAlive(int pid, String tenantCode) {
+        try {
+            // Use kill -0 to check if the process exists; it does not actually send a signal
+            String checkCmd = String.format("kill -0 %d", pid);
+            checkCmd = OSUtils.getSudoCmd(tenantCode, checkCmd);
+            OSUtils.exeCmd(checkCmd);

Review Comment:
   I found that `OSUtils.exeCmd` would not return any result or exit code or throw exception if command run normally but exit code is not 0. We need to find a new way to verify the exit code is 0 or not. Otherwise this will always equal true.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047241770

   > UT also failed. Please check it. @njnu-seafish
   
   update


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3036697134

   > I've tested this issue #17316 base on your reproduction steps in macos and ubuntu 24.04 and found this issue does not exist, please describe the specific reproduction environment. @njnu-seafish
   
   After fixing the bug according to the code above, the log of the task instance is as follows.
   `
   Final Shell file is: 
   ****************************** Script Content *****************************************************************
   #!/bin/bash
   BASEDIR=$(cd `dirname $0`; pwd)
   cd $BASEDIR
   source /usr/local/dolphinscheduler/bin/env/dolphinscheduler_env.sh
   echo ${JAVE_HOME}
   sleep 10m
   ****************************** Script Content *****************************************************************
   
   Executing shell command : sudo -u dolphinscheduler -i /data01/dolphinscheduler/exec/process/130/130.sh
   
   process start, process id is: 643464
   
   Begin killing task instance, processId: 643464
   
   prepare to parse pid, raw pid string: sudo(643464)---130.sh(643479)---sleep(643559)
   
   Kill command: kill -s SIGINT 643464 643479 643559, trying to terminate process
   
   Kill command: sudo -u dolphinscheduler -i kill -s SIGINT 643464 643479 643559, kill failed, the process: 643464 is still running
   
   Kill command: kill -s SIGTERM 643464 643479 643559, trying to terminate process
   
   Kill command: sudo -u dolphinscheduler -i kill -s SIGTERM 643464 643479 643559, kill succeeded
   
   Successfully killed process tree using SIGTERM, processId: 643464
   
   Process tree for task: 130 is killed or already finished, pid: 643464
   
   `


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2193781528


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
           // 1. Try to terminate gracefully (SIGINT)
           boolean gracefulKillSuccess = sendKillSignal("SIGINT", pids, request.getTenantCode());
           if (gracefulKillSuccess) {
               log.info("Successfully killed process tree using SIGINT, processId: {}", processId);
               return true;
           }
   
           The key issue is that the soft kill returns success, but the physical process is not actually killed, so we need to add a check process status logic.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2193823938


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   > I think it's better used for waiting the soft kill result. If it timeout then hard kill. This seems make little sense if only wait the process exit. If it doesn't exit, then you should not return.
   
   
   In actual development and operations, do not use SIGKILL right away, as it deprives the process of the opportunity to clean up resources. The recommended approach is:
   
   First send SIGINT, wait for a certain amount of time (e.g., 5–10 seconds), and check the process status.
   
   If the process hasn't exited, send SIGTERM, wait again (e.g., 5–10 seconds), and check the process status.
   
   If the process still hasn't exited, then send SIGKILL.
   
   A key point: even if SIGINT returns successfully, the process may still be running. Therefore, it's essential to add a check logic to confirm whether the process has truly exited.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2189800439


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +155,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
+            log.info("Kill command: {}, trying to terminate process", killCmd);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);
+
+            // 3. Check if the processes are still running
+            String[] pidArray = PID_PATTERN.split(pids);
+            for (String pid : pidArray) {
+                // Check if each PID is still alive
+                if (isProcessAlive(Integer.parseInt(pid))) {
+                    log.info("Kill command: {}, kill failed, the process: {} is still running", killCmd, pid);
+                    // Return false if any process is still alive
+                    return false;
+                }
+            }
+            log.info("Kill command: {}, kill succeeded", killCmd);
+            // All processes have been successfully terminated
             return true;
         } catch (Exception e) {
             log.error("Error sending {} to process: {}", signal, pids, e);
             return false;
         }
     }
 
+    /**
+     * Check if a process with the specified PID is alive.
+     *
+     * @param pid the process ID to check
+     * @return true if the process exists and is running, false otherwise
+     */
+    private static boolean isProcessAlive(int pid) {
+        try {
+            // Use kill -0 to check if the process exists; it does not actually send a signal
+            String checkCmd = String.format("kill -0 %d", pid);
+            OSUtils.exeCmd(checkCmd);

Review Comment:
   Yes,I‘m sorry.  I've already made the changes based on your suggestions. thanks



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2193935570


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +156,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);

Review Comment:
   Once send SIGINT/SIGTERM, the process might have some work to do, so the process will not exist directly, the process can ignore the sig, so we need to check during a window, if timeout and the process exist, then need to kill -9.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2209385125


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java:
##########
@@ -132,7 +132,7 @@ void testKillProcessSuccessWithSigInt() throws Exception {
         boolean result = ProcessUtils.kill(taskRequest);
 
         // Assert
-        Assertions.assertTrue(result);
+        Assertions.assertFalse(result);

Review Comment:
   > Why change the assertion? Please fix the test case.
   
   update the test case, it is ok now.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2212092396


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -100,29 +114,32 @@
 
             // Get all child processes
             String pids = getPidsStr(processId);
-            String[] pidArray = pids.split("\\s+");
+            String[] pidArray = PID_PATTERN.split(pids);
             if (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());

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/5471)



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2207653180


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -100,29 +114,35 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
 
             // Get all child processes
             String pids = getPidsStr(processId);
-            String[] pidArray = pids.split("\\s+");
+            String[] pidArray = PID_PATTERN.split(pids);
             if (pidArray.length == 0) {
                 log.warn("No valid PIDs found for process: {}", processId);
                 return true;
             }
 
+            // Convert PID string to list of integers
+            List<Integer> pidList = new ArrayList<>();

Review Comment:
   [nitpick] You can simplify PID string parsing by using streams, e.g.: `List<Integer> pidList = Arrays.stream(pidArray).map(Integer::parseInt).collect(Collectors.toList());` to reduce boilerplate.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3036660060

   > I've tested this issue #17316 base on your reproduction steps in macos and ubuntu 24.04 and found this issue does not exist, please describe the specific reproduction environment. @njnu-seafish
   
   Sorry, I was very busy during the day and didn't have time to reply.
   My environment is centos7.
   Below is an example I tested directly on my machine.
   `
   [dolphinscheduler@xxxxx][~]
   $ more test.sh 
   echo ${JAVE_HOME};
   sleep 10m
   
   
   [dolphinscheduler@xxxxx][~]
   $ date
   Fri Jul  4 22:59:27 CST 2025
   
   
   [dolphinscheduler@xxxxx][~]
   $ sudo -u dolphinscheduler -i sh test.sh 
   
   
   [dolphinscheduler@xxxxx][~]
   $ ps -ef | grep -i test.sh
   root     1259617 1258564  0 22:59 pts/5    00:00:00 sudo -u dolphinscheduler -i sh test.sh
   
   
   [dolphinscheduler@xxxxx][~]
   $ pstree -p 1259617
   sudo(1259617)───sh(1259618)───sleep(1259696)
   
   
   [dolphinscheduler@xxxxx][~]
   $ pstree -p 1259617
   sudo(1259617)───sh(1259618)───sleep(1259696)
   
   // kill -s SIGINT return 0.  However, the process was not actually killed.
   [dolphinscheduler@xxxxx][~]
   $ sudo -u dolphinscheduler kill -s SIGINT 1259617 1259618 1259696
   
   [dolphinscheduler@xxxxx][~]
   $ echo $?
   0
   
   // wating 5m
   [dolphinscheduler@xxxxx][~]
   $ date
   Fri Jul  4 23:04:19 CST 2025
   
   [dolphinscheduler@xxxxx][~]
   $ ps -ef | grep -i test.sh
   root     1259617 1258564  0 22:59 pts/5    00:00:00 sudo -u dolphinscheduler -i sh test.sh
   
   
   [dolphinscheduler@xxxxx][~]
   $ pstree -p 1259617
   sudo(1259617)───sh(1259618)───sleep(1259696)
   
   `
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after kill [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2188804704


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -56,6 +56,9 @@
 @Slf4j
 public final class ProcessUtils {
 
+    // Wait 5 seconds to check process status
+    private static final int CHECK_PROCESS_WAITING_MILLIS = 5000;

Review Comment:
   Explicit waiting is not a good way for user experience. Some programs take some time to shut down gracefully. We should set this as an implicit wait and put this time in the configuration file for the user to configure.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047947811

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [36.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047948614

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [36.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3087481043

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17320&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [91.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS merged PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2192232097


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   I think it's better used for waiting the soft kill result. If it timeout then hard kill. This seems make little sense if only wait the process exit. If it doesn't exit, then you should not return.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2206085730


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -100,29 +113,39 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
 
             // Get all child processes
             String pids = getPidsStr(processId);
-            String[] pidArray = pids.split("\\s+");
+            String[] pidArray = PID_PATTERN.split(pids);
             if (pidArray.length == 0) {
                 log.warn("No valid PIDs found for process: {}", processId);
                 return true;
             }
 
+            // Convert PID string to list of integers
+            List<Integer> pidList = new ArrayList<>();
+            for (String pidStr : pidArray) {
+                try {
+                    pidList.add(Integer.parseInt(pidStr));
+                } catch (NumberFormatException e) {
+                    log.warn("Invalid PID: {}", pidStr);

Review Comment:
   // Convert PID string to list of integers
               List<Integer> pidList = new ArrayList<>();
               for (String pidStr : pidArray) {
                   pidList.add(Integer.parseInt(pidStr));
               }                
   The outer try-catch block will capture and handle the exception.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2212643059


##########
deploy/kubernetes/dolphinscheduler/Chart.yaml:
##########
@@ -35,11 +35,11 @@ type: application
 
 # This is the chart version. This version number should be incremented each time you make changes
 # to the chart and its templates, including the app version.
-version: 3.1.0
+version: 3.1.1

Review Comment:
   Why change this?



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2191971762


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +156,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);

Review Comment:
   It's better to use while to check whether the process is still alive, if it still alive after timeout, then use `kill -9`



##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   ```suggestion
   | conf.common."shell.kill.wait.timeout" | int | `30` | If the shell process still active after this value, then will use kill -9 to kill it(in seconds) |
   ```



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2191360360


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +155,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);
+
+            // 3. Check if the processes are still running
+            String[] pidArray = PID_PATTERN.split(pids);
+            for (String pid : pidArray) {
+                // Check if each PID is still alive
+                if (isProcessAlive(Integer.parseInt(pid), tenantCode)) {
+                    log.info("Kill command: {}, kill failed, the process: {} is still running", killCmd, pid);
+                    // Return false if any process is still alive
+                    return false;
+                }
+            }
+            log.debug("Kill command: {}, kill succeeded", killCmd);
+            // All processes have been successfully terminated
             return true;
         } catch (Exception e) {
             log.error("Error sending {} to process: {}", signal, pids, e);
             return false;
         }
     }
 
+    /**
+     * Check if a process with the specified PID is alive.
+     *
+     * @param pid the process ID to check
+     * @return true if the process exists and is running, false otherwise
+     */
+    private static boolean isProcessAlive(int pid, String tenantCode) {
+        try {
+            // Use kill -0 to check if the process exists; it does not actually send a signal
+            String checkCmd = String.format("kill -0 %d", pid);
+            checkCmd = OSUtils.getSudoCmd(tenantCode, checkCmd);
+            OSUtils.exeCmd(checkCmd);

Review Comment:
   I was wrong. It would throw `ExitCodeException`. Please ignore it.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2192160475


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   Sorry,I'm a bit confused.   "shell.kill.wait.timeout"?  the time is for wating to check process status after killing



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2197084167


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +156,54 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);

Review Comment:
   Thank you so much for your suggestions! I've made revisions based on your input. Could you kindly review it again? Thanks a lot!



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2197080629


##########
deploy/kubernetes/dolphinscheduler/README.md:
##########
@@ -141,6 +141,7 @@ Please refer to the [Quick Start in Kubernetes](../../../docs/docs/en/guide/inst
 | conf.common."login.user.keytab.username" | string | `"hdfs-mycluster@ESZ.COM"` | login user from keytab username |
 | conf.common."ml.mlflow.preset_repository" | string | `"https://github.com/apache/dolphinscheduler-mlflow"` | mlflow task plugin preset repository |
 | conf.common."ml.mlflow.preset_repository_version" | string | `"main"` | mlflow task plugin preset repository version |
+| conf.common."process.status.check.delay" | int | `5` | The delay before checking the shell process status after termination (in seconds) |

Review Comment:
   Thank you so much for your suggestions! 



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047168033

   Please run `mvn spotless:apply` to format the code. @njnu-seafish 


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3047326100

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [36.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17320&metric=new_coverage&view=list) (required ≥ 60%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17320)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3068587224

   > ## Pull Request Overview
   > This PR adds a configurable timeout for waiting on shell process termination and enhances the kill logic to poll process status after sending kill signals. It also updates various resource configurations and bumps the Kubernetes Helm chart version.
   > 
   > * Introduce `shell.kill.wait.timeout` property in common configs and add `SHELL_KILL_WAIT_TIMEOUT` constant
   > * Refactor `ProcessUtils.kill` to parse PIDs into a list, send signals, and poll until processes exit
   > * Update E2E/test properties, document new config in Helm values and README, and bump chart version
   > 
   > ### Reviewed Changes
   > Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
   > 
   > Show a summary per file
   > File	Description
   > dolphinscheduler-task-plugin/.../common.properties	Add `shell.kill.wait.timeout` property
   > ProcessUtils.java	Parse PIDs into `List<Integer>`, implement polling with timeout, add `isProcessAlive`
   > dolphinscheduler-e2e/.../common.properties	Add timeout property and fix `appId.collect` syntax
   > dolphinscheduler-common/.../common.properties	Add `shell.kill.wait.timeout` to test and main resources
   > Constants.java	Add `SHELL_KILL_WAIT_TIMEOUT` constant
   > values.yaml	Add `shell.kill.wait.timeout` under `conf`
   > README.md	Document `shell.kill.wait.timeout` in chart config
   > Chart.yaml	Bump `version` and `appVersion` to 3.1.1
   > Comments suppressed due to low confidence (4)
   > **dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java:75**
   > 
   > * [nitpick] The Javadoc for this constant is minimal. Consider expanding it to explain that this property defines the wait timeout in seconds before using SIGKILL.
   > 
   > ```
   >     public static final String SHELL_KILL_WAIT_TIMEOUT = "shell.kill.wait.timeout";
   > ```
   > 
   > **dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:54**
   > 
   > * It looks like `List` and `ArrayList` are used later in this class but not imported here. Please add `import java.util.List;` and `import java.util.ArrayList;` to avoid compile errors.
   > 
   > ```
   > import java.util.stream.Collectors;
   > ```
   > 
   > **dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:168**
   > 
   > * [nitpick] Mutating the original `pidList` inside this method can lead to side effects if the list is reused elsewhere. Consider making a defensive copy of the list before polling/removal.
   > 
   > ```
   >     private static boolean sendKillSignal(String signal, List<Integer> pidList, String tenantCode) {
   > ```
   > 
   > **dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:188**
   > 
   > * [nitpick] The multiplication here assumes `SLEEP_TIME_MILLIS` maps directly to milliseconds. It might be clearer to calculate `timeoutMillis = TimeUnit.SECONDS.toMillis(SHELL_KILL_WAIT_TIMEOUT)` or document the relationship explicitly.
   > 
   > ```
   >             long timeoutMillis = SLEEP_TIME_MILLIS * SHELL_KILL_WAIT_TIMEOUT;
   > ```
   
   Please take care about the comment from copilot.


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2212707962


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java:
##########
@@ -125,16 +155,76 @@ void testKillProcessSuccessWithSigInt() throws Exception {
                 .thenReturn("kill -s SIGINT 12345");
         mockedOSUtils.when(() -> OSUtils.exeCmd("kill -s SIGINT 12345")).thenReturn("");
 
-        // Mock process check - process dies after SIGINT
-        mockedOSUtils.when(() -> OSUtils.exeCmd("ps -p 12345")).thenReturn(null);
+        // Mock kill -0
+        mockedOSUtils.when(() -> OSUtils.getSudoCmd(Mockito.eq("testTenant"), Mockito.matches("kill -0.*")))
+                .thenReturn("kill -0 12345");
+        // Initialize a counter to track how many times the method is invoked
+        AtomicInteger callCount = new AtomicInteger(0);
+        // Mock the static method OSUtils.exeCmd that matches "kill -0" command
+        mockedOSUtils.when(() -> OSUtils.exeCmd(Mockito.matches(".*kill -0.*")))
+                .thenAnswer(invocation -> {
+                    int count = callCount.incrementAndGet();
+                    // these calls will succeed (simulate process is alive)
+                    if (count == 1 || count == 2) {
+                        return "";
+                    } else {
+                        throw new RuntimeException("Command failed");
+                    }
+                });

Review Comment:
   The AtomicInteger with hardcoded call count logic (count == 1 || count == 2) makes the test brittle and difficult to understand. Consider using a more explicit mock setup with predefined responses.
   ```suggestion
           // Mock the static method OSUtils.exeCmd that matches "kill -0" command
           mockedOSUtils.when(() -> OSUtils.exeCmd(Mockito.matches(".*kill -0.*")))
                   .thenReturn("") // First invocation succeeds (process is alive)
                   .thenReturn("") // Second invocation succeeds (process is alive)
                   .thenThrow(new RuntimeException("Command failed")); // Subsequent invocations fail (process is no longer alive)
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -139,23 +156,100 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
     /**
      * Send a kill signal to a process group
      * @param signal Signal type (SIGINT, SIGTERM, SIGKILL)
-     * @param pids Process ID list
+     * @param pidList Process ID list
      * @param tenantCode Tenant code
      */
-    private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
+    private static boolean sendKillSignal(String signal, List<Integer> pidList, String tenantCode) {
+        if (pidList == null || pidList.isEmpty()) {
+            log.info("No process needs to be killed.");
+            return true;
+        }
+
+        List<Integer> alivePidList = getAlivePidList(pidList, tenantCode);
+        if (alivePidList.isEmpty()) {
+            log.info("All processes already terminated.");
+            return true;
+        }
+
+        String pids = alivePidList.stream()
+                .map(String::valueOf)
+                .collect(Collectors.joining(" "));
+
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
-            return true;
+            // 2. Wait for the processes to terminate with a timeout-based polling mechanism
+            // Max wait time
+            long timeoutMillis = TimeUnit.SECONDS.toMillis(SHELL_KILL_WAIT_TIMEOUT);
+
+            long startTime = System.currentTimeMillis();
+            while (!alivePidList.isEmpty() && (System.currentTimeMillis() - startTime < timeoutMillis)) {
+                // Remove if process is no longer alive
+                alivePidList.removeIf(pid -> !isProcessAlive(pid, tenantCode));
+                if (!alivePidList.isEmpty()) {
+                    // Wait for a short interval before checking process statuses again, to avoid excessive CPU usage
+                    // from tight-loop polling.
+                    ThreadUtils.sleep(SLEEP_TIME_MILLIS);

Review Comment:
   [nitpick] The polling mechanism uses a fixed sleep interval which may not be optimal. Consider using exponential backoff or a configurable polling interval to balance responsiveness with CPU usage.
   ```suggestion
               long initialSleepMillis = 100; // Start with 100ms
               long maxSleepMillis = 2000; // Cap the sleep interval at 2000ms
               long currentSleepMillis = initialSleepMillis;
   
               while (!alivePidList.isEmpty() && (System.currentTimeMillis() - startTime < timeoutMillis)) {
                   // Remove if process is no longer alive
                   alivePidList.removeIf(pid -> !isProcessAlive(pid, tenantCode));
                   if (!alivePidList.isEmpty()) {
                       // Wait for a dynamically adjusted interval before checking process statuses again
                       ThreadUtils.sleep(currentSleepMillis);
                       // Increase the sleep interval exponentially, up to the maximum limit
                       currentSleepMillis = Math.min(currentSleepMillis * 2, maxSleepMillis);
                   } else {
                       // Reset the sleep interval if all processes are terminated
                       currentSleepMillis = initialSleepMillis;
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -139,23 +156,100 @@ public static boolean kill(@NonNull TaskExecutionContext request) {
     /**
      * Send a kill signal to a process group
      * @param signal Signal type (SIGINT, SIGTERM, SIGKILL)
-     * @param pids Process ID list
+     * @param pidList Process ID list
      * @param tenantCode Tenant code
      */
-    private static boolean sendKillSignal(String signal, String pids, String tenantCode) {
+    private static boolean sendKillSignal(String signal, List<Integer> pidList, String tenantCode) {
+        if (pidList == null || pidList.isEmpty()) {
+            log.info("No process needs to be killed.");
+            return true;
+        }
+
+        List<Integer> alivePidList = getAlivePidList(pidList, tenantCode);
+        if (alivePidList.isEmpty()) {
+            log.info("All processes already terminated.");
+            return true;
+        }
+
+        String pids = alivePidList.stream()
+                .map(String::valueOf)
+                .collect(Collectors.joining(" "));
+
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
-            return true;
+            // 2. Wait for the processes to terminate with a timeout-based polling mechanism
+            // Max wait time
+            long timeoutMillis = TimeUnit.SECONDS.toMillis(SHELL_KILL_WAIT_TIMEOUT);
+
+            long startTime = System.currentTimeMillis();
+            while (!alivePidList.isEmpty() && (System.currentTimeMillis() - startTime < timeoutMillis)) {
+                // Remove if process is no longer alive
+                alivePidList.removeIf(pid -> !isProcessAlive(pid, tenantCode));

Review Comment:
   [nitpick] The while loop modifies `alivePidList` during iteration with `removeIf()`. While this is safe for ArrayList, it could be made more explicit by collecting results separately to avoid potential confusion.
   ```suggestion
                   // Collect PIDs that are still alive
                   List<Integer> stillAlivePids = alivePidList.stream()
                           .filter(pid -> isProcessAlive(pid, tenantCode))
                           .collect(Collectors.toList());
   
                   alivePidList = stillAlivePids;
   ```



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-17316][Task-API] Add check process status after killing task [dolphinscheduler]

Posted by "njnu-seafish (via GitHub)" <gi...@apache.org>.
njnu-seafish commented on PR #17320:
URL: https://github.com/apache/dolphinscheduler/pull/17320#issuecomment-3086553005

   Unit test results varied across different operating systems (e.g., Linux, macOS, Windows), primarily due to:
   
    mockedOSUtils.when(() -> OSUtils.exeCmd(Mockito.matches(".*pstree.*12345"))).thenReturn("1234 12345");
    
    mockedOSUtils.when(() -> OSUtils.exeCmd(Mockito.matches(".*pstree.*12345"))).thenReturn("sudo(12345)---86.sh(1234)");
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org