{"record":{"id":"6c52545686bf43d5","repo":"apache/dolphinscheduler","slug":"cancel-application-failed","errorCode":null,"errorMessage":"Cancel application failed!","messagePattern":"Cancel application failed!","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java","lineNumber":374,"sourceCode":"                                    taskExecutionContext.getK8sTaskExecutionContext(),\n                                    taskExecutionContext.getTaskAppId(), \"\"));\n                }\n            } else {\n                String host = taskExecutionContext.getHost();\n                String executePath = taskExecutionContext.getExecutePath();\n                String tenantCode = taskExecutionContext.getTenantCode();\n                List<String> appIds;\n                if (StringUtils.isNotEmpty(taskExecutionContext.getAppIds())) {\n                    // is failover\n                    appIds = Arrays.asList(taskExecutionContext.getAppIds().split(COMMA));\n                } else {\n                    String logPath = taskExecutionContext.getLogPath();\n                    String appInfoPath = taskExecutionContext.getAppInfoPath();\n                    if (logPath == null || appInfoPath == null || executePath == null || tenantCode == null) {\n                        log.error(\n                                \"Kill yarn job error, the input params is illegal, host: {}, logPath: {}, appInfoPath: {}, executePath: {}, tenantCode: {}\",\n                                host, logPath, appInfoPath, executePath, tenantCode);\n                        throw new TaskException(\"Cancel application failed!\");\n                    }\n                    log.info(\"Get appIds from worker {}, taskLogPath: {}\", host, logPath);\n                    appIds = LogUtils.getAppIds(logPath, appInfoPath,\n                            PropertyUtils.getString(APPID_COLLECT, DEFAULT_COLLECT_WAY));\n                    taskExecutionContext.setAppIds(String.join(TaskConstants.COMMA, appIds));\n                }\n                if (CollectionUtils.isEmpty(appIds)) {\n                    log.info(\"The appId is empty\");\n                    return;\n                }\n                ApplicationManager applicationManager = applicationManagerMap.get(ResourceManagerType.YARN);\n                applicationManager.killApplication(new YarnApplicationManagerContext(executePath, tenantCode, appIds));\n                log.info(\"yarn application [{}] is killed or already finished\", appIds);\n            }\n        } catch (Exception e) {\n            log.error(\"Cancel application failed: {}\", e.getMessage());\n        }\n    }","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java#L356-L392","documentation":"ProcessUtils.cancelApplication() kills a Yarn application associated with a task. Before doing so it requires logPath, appInfoPath, executePath, and tenantCode; if any is null it logs the offending inputs and throws TaskException 'Cancel application failed!'. The kill cannot proceed without these paths to locate the appIds.","triggerScenarios":"Canceling a task on a Yarn host when the TaskExecutionContext has a null logPath, appInfoPath, executePath, or tenantCode — e.g. execution directory was never created, app info file not configured, or tenant resolution failed.","commonSituations":"Killing a task that failed early (paths never populated); workers with misconfigured resource/tmp storage directories; Hadoop/Yarn tasks where appIds collection (APPID_COLLECT) settings disabled app-info output; task state mismatch after worker restart.","solutions":["Read the preceding log.error line — it lists exactly which parameter(s) are null.","Ensure the task execution directory (executePath) and tenant code are correctly set in the task context.","Verify the Yarn task produces appInfoPath (appIds file) — check APPID_COLLECT config (log vs application_url).","Confirm logPath points to an existing task log on the target host.","If the app already finished, treat this as non-fatal cleanup and skip the kill."],"exampleFix":"// before\n// cancel path with null appInfoPath (task failed before submission)\nprocessUtils.cancelApplication(taskExecutionContext, host);\n// after\nif (taskExecutionContext.getAppInfoPath() != null && new File(taskExecutionContext.getLogPath()).exists()) {\n    processUtils.cancelApplication(taskExecutionContext, host);\n} else {\n    log.info(\"no yarn app to cancel for task {}\", taskExecutionContext.getTaskInstanceId());\n}","handlingStrategy":"validation","validationCode":"TaskExecutionContext ctx = taskExecutionContext;\nif (ctx.getLogPath() == null || ctx.getAppInfoPath() == null ||\n    ctx.getExecutePath() == null || ctx.getTenantCode() == null) {\n    log.warn(\"skip yarn cancel: incomplete context (log/appInfo/executePath/tenantCode)\");\n    return;\n}","typeGuard":"boolean canCancelYarn(TaskExecutionContext c) {\n    return c != null && c.getLogPath() != null && c.getAppInfoPath() != null\n        && c.getExecutePath() != null && c.getTenantCode() != null;\n}","tryCatchPattern":"try {\n    ProcessUtils.cancelApplication(ctx, host);\n} catch (TaskException e) {\n    log.warn(\"yarn cancel failed (context may be incomplete)\", e); // non-fatal for cleanup\n}","preventionTips":["Populate executePath, logPath, appInfoPath and tenantCode before any task that may hit Yarn.","Configure app-id collection (APPID_COLLECT) so appInfoPath is always written.","Treat cancel-time failures as best-effort cleanup in your cancellation flow."],"tags":["yarn","task-cancel","task-exception"],"backgroundTag":"missing-required-argument","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"}