{"record":{"id":"46157d3ad3208c15","repo":"apache/dolphinscheduler","slug":"cancel-application-error-46157d","errorCode":null,"errorMessage":"cancel application error","messagePattern":"cancel application error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"warning","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java","lineNumber":91,"sourceCode":"        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            log.error(\"The current Shell task has been interrupted\", e);\n            setExitStatusCode(EXIT_CODE_FAILURE);\n            throw new TaskException(\"The current Shell task has been interrupted\", e);\n        } catch (Exception e) {\n            log.error(\"shell task error\", e);\n            setExitStatusCode(EXIT_CODE_FAILURE);\n            throw new TaskException(\"Execute shell task error\", e);\n        }\n    }\n\n    @Override\n    public void cancel() throws TaskException {\n        // cancel process\n        try {\n            shellCommandExecutor.cancelApplication();\n        } catch (Exception e) {\n            throw new TaskException(\"cancel application error\", e);\n        }\n    }\n\n    @Override\n    public AbstractParameters getParameters() {\n        return shellParameters;\n    }\n\n}\n","sourceCodeStart":73,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java#L73-L101","documentation":"ShellTask.cancel() delegates to ShellCommandExecutor.cancelApplication() to kill the running process. Any exception during the cancel (e.g. the process handle is invalid or the executor was never started) is wrapped as TaskException(\"cancel application error\"). This means the task could not be stopped cleanly; the original process may still be running.","triggerScenarios":"Calling cancel() on a ShellTask whose shell process has already exited or whose shellCommandExecutor was not initialized (init() failed earlier); kill issued via ProcessBuilder/OS while the process object is in an unexpected state.","commonSituations":"Double-clicking kill on a task (second cancel hits an already-dead process); cancelling a task that failed during init() before the executor existed; orphaned processes on the worker after an abrupt worker crash.","solutions":["Retry the cancel after a short delay if the process was still starting; otherwise ignore the failure since the process already exited","If processes keep running, kill leftovers on the worker host (check with ps for the task's shell process) and clean up the task instance","Check the wrapped exception: if the executor was null, fix the init() failure first — cancel cannot work without a started executor"],"exampleFix":"// before: cancel on never-initialized task\nTaskExecutionContext ctx = ...; // params invalid, init() failed\nshellTask.cancel(); // throws 'cancel application error'\n// after: check state before cancelling\nif (taskInstance.getState() == ExecutionStatus.RUNNING_EXECUTION) {\n    shellTask.cancel();\n}","handlingStrategy":"try-catch","validationCode":"boolean cancellable = taskInstance.getState() == ExecutionStatus.RUNNING_EXECUTION\n        && shellTask != null;","typeGuard":null,"tryCatchPattern":"try {\n    shellTask.cancel();\n} catch (TaskException e) {\n    // process likely already exited; check cause, don't fail the kill pipeline\n    log.warn(\"cancel failed (process may be gone)\", e);\n}","preventionTips":["Only cancel tasks in a running state","Fix init() failures before attempting cancel — a failed init leaves no executor to cancel","Reconcile leftover worker processes after abrupt worker crashes"],"tags":["cancel","process","lifecycle"],"backgroundTag":"task-execution-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}