rickchengx commented on code in PR #13689:
URL:
https://github.com/apache/dolphinscheduler/pull/13689#discussion_r1129000466
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java:
##########
@@ -278,53 +276,18 @@ public String getVarPool() {
return varPool.toString();
}
- /**
- * cancel application
- *
- * @throws Exception exception
- */
- public void cancelApplication() throws Exception {
+ public void cancelApplication() {
if (process == null) {
return;
}
- int processId = getProcessId(process);
- logger.info("Begin to kill process process, pid is : {}", processId);
- // kill , waiting for completion
- boolean alive = softKill(processId);
-
- if (alive) {
- String cmd = String.format("kill -9 %s", getPidsStr(processId));
- cmd = OSUtils.getSudoCmd(taskRequest.getTenantCode(), cmd);
- OSUtils.exeCmd(cmd);
- logger.info("Success kill task: {}, pid: {}, cmd: {}",
taskRequest.getTaskAppId(), processId, cmd);
- } else {
- logger.info("The process: {} is not alive, no need to kill",
processId);
+ // soft kill
+ logger.info("Begin to kill process process, pid is : {}",
taskRequest.getProcessId());
+ process.destroy();
+ if (process.isAlive()) {
+ process.destroyForcibly();
Review Comment:
Hi, @ruanwenjun , i think its great to use `process.destroy()` instead of
kill command.
What if wait for a period of time after `process.destroy()`, if the process
still has not stopped, then call `destroyForcibly()`
This way the process can have time to do things that need to be processed
before stopping
maybe something like:
```
try {
process.destroy();
if (!process.waitFor(5, TimeUnit.SECONDS)) {
process.destroyForcibly();
}
}
catch (InterruptedException e) {
process.destroyForcibly();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]