{"record":{"id":"d6de3d80246bd7c4","repo":"apache/dolphinscheduler","slug":"cancel-application-error-d6de3d","errorCode":null,"errorMessage":"cancel application error","messagePattern":"cancel application error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java","lineNumber":107,"sourceCode":"            setExitStatusCode(taskResponse.getExitStatusCode());\n            setProcessId(taskResponse.getProcessId());\n            setTaskOutputParams(shellCommandExecutor.getTaskOutputParams());\n            pythonParameters.dealOutParam(shellCommandExecutor.getTaskOutputParams());\n            taskRequest.setVarPool(pythonParameters.getVarPool());\n        } catch (Exception e) {\n            log.error(\"python task failure\", e);\n            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);\n            throw new TaskException(\"run python 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 pythonParameters;\n    }\n\n    /**\n     * create python command file if not exists\n     *\n     * @param pythonScript     exec python script\n     * @param pythonScriptFile python script file\n     * @throws IOException io exception\n     */\n    protected void createPythonCommandFileIfNotExists(String pythonScript, String pythonScriptFile) throws IOException {\n        log.info(\"tenantCode :{}, task dir:{}\", taskRequest.getTenantCode(), taskRequest.getExecutePath());\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java#L89-L125","documentation":"PythonTask.cancel attempts to cancel the running shell application via shellCommandExecutor.cancelApplication(); any exception there is wrapped into TaskException(\"cancel application error\"). It means the task could not be killed/aborted cleanly, so the underlying process may still be running.","triggerScenarios":"Calling cancel() (e.g., user clicks stop, timeout kill, worker graceful shutdown) when the shell process has already exited, the process handle is invalid, or killCommand execution throws an IOException/InterruptedException.","commonSituations":"Stopping a task that already finished (race between completion and kill); worker process table issues; permissions preventing pkill/kill of the child process.","solutions":["Check the cause: if the process already terminated, the cancel failure is benign and can be ignored.","Verify the worker user has permission to kill the task's child processes (same OS user as the executing task).","Inspect shellCommandExecutor/kill command logs for the pid used and any OS-level kill errors.","Retry cancel if it failed transiently (e.g., InterruptedException during process wait)."],"exampleFix":"// before\n} catch (Exception e) {\n    throw new TaskException(\"cancel application error\", e);\n}\n// after: tolerate already-dead process\n} catch (Exception e) {\n    log.warn(\"cancel python task failed, process may have already exited\", e);\n    throw new TaskException(\"cancel application error: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    pythonTask.cancel();\n} catch (TaskException e) {\n    // treat 'process already exited' as benign\n    logger.warn(\"Cancel failed (task may have completed): {}\", e.getMessage());\n}","preventionTips":["Expect cancel races with task completion and treat them as non-fatal.","Ensure the task runs under a worker user that can kill its own children.","Monitor for orphaned processes after failed cancels."],"tags":["task-cancel","python","process-kill","shell-executor"],"backgroundTag":"process-kill-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"}