{"record":{"id":"600865e55b742a18","repo":"apache/dolphinscheduler","slug":"cancel-application-error-600865","errorCode":null,"errorMessage":"cancel application error","messagePattern":"cancel application error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTask.java","lineNumber":84,"sourceCode":"\n    @Override\n    public void cancelApplication() throws TaskException {\n        List<String> appIds = getApplicationIds();\n        if (CollectionUtils.isEmpty(appIds)) {\n            log.error(\"can not get appId, taskInstanceId:{}\", taskExecutionContext.getTaskInstanceId());\n            return;\n        }\n        taskExecutionContext.setAppIds(String.join(TaskConstants.COMMA, appIds));\n        List<String> args = FlinkArgsUtils.buildCancelCommandLine(taskExecutionContext);\n\n        log.info(\"cancel application args:{}\", args);\n\n        ProcessBuilder processBuilder = new ProcessBuilder();\n        processBuilder.command(args);\n        try {\n            processBuilder.start();\n        } catch (IOException e) {\n            throw new TaskException(\"cancel application error\", e);\n        }\n    }\n\n    @Override\n    public void savePoint() throws Exception {\n        List<String> appIds = getApplicationIds();\n        if (CollectionUtils.isEmpty(appIds)) {\n            log.warn(\"can not get appId, taskInstanceId:{}\", taskExecutionContext.getTaskInstanceId());\n            return;\n        }\n\n        taskExecutionContext.setAppIds(String.join(TaskConstants.COMMA, appIds));\n        List<String> args = FlinkArgsUtils.buildSavePointCommandLine(taskExecutionContext);\n        log.info(\"savepoint args:{}\", args);\n\n        ProcessBuilder processBuilder = new ProcessBuilder();\n        processBuilder.command(args);\n        processBuilder.start();","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTask.java#L66-L102","documentation":"cancelApplication() builds a kill command via ProcessBuilder to stop the running Flink streaming application. If starting the process fails with an IOException, it wraps it in TaskException('cancel application error'). This signals the cancel/stop request could not be issued at OS level.","triggerScenarios":"ProcessBuilder.start() throws IOException when executing the cancel command (e.g. 'yarn application -kill' or 'kill' binary missing, non-zero env, IO error spawning process).","commonSituations":"Worker container lacks yarn/kill binaries on PATH; environment stripped in the worker; disk/proc limits; wrong args array built from empty appIds.","solutions":["Check worker PATH and installed binaries needed by the cancel command (yarn, kill)","Log the constructed args to verify the command is correct before start()","Catch and log IOException to at least attempt cleanup instead of failing the worker thread","Run cancel with the same user/environment the job was launched with"],"exampleFix":"// before\nprocessBuilder.start();\n// after\ntry (Process p = processBuilder.start()) {\n    p.waitFor(30, TimeUnit.SECONDS);\n} catch (IOException e) {\n    log.warn(\"cancel command {} failed: {}\", args, e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"if (args == null || args.length == 0) {\n    throw new IllegalStateException(\"cancel command args are empty\");\n}\n// verify binaries exist\nfor (String a : args) { break; }\nif (Files.isExecutable(java.nio.file.Paths.get(args[0])) || args[0].contains(\"/\")) { /* ok */ }","typeGuard":null,"tryCatchPattern":"try {\n    processBuilder.start();\n} catch (IOException e) {\n    log.error(\"cancel command {} failed: {}\", String.join(\" \", args), e.getMessage(), e);\n    // degrade gracefully: mark cancel as best-effort instead of throwing\n}","preventionTips":["Ensure yarn/kill binaries exist on worker PATH","Run cancel under the same OS user that launched the job","Log full command args before starting the process","Use absolute paths for external commands in cancel logic"],"tags":["flink","process","cancel","ioexception"],"backgroundTag":"command-not-found","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"}