{"record":{"id":"44e1294480d29bcd","repo":"apache/dolphinscheduler","slug":"cancel-application-error-44e129","errorCode":null,"errorMessage":"cancel application error","messagePattern":"cancel application error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java","lineNumber":118,"sourceCode":"            String localFile = buildCommand();\n            int exitCode = remoteExecutor.run(taskId, localFile);\n            setExitStatusCode(exitCode);\n            remoteShellParameters.dealOutParam(remoteExecutor.getTaskOutputParams());\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            log.info(\"kill remote task {}\", taskId);\n            remoteExecutor.kill(taskId);\n        } catch (Exception e) {\n            throw new TaskException(\"cancel application error\", e);\n        }\n    }\n\n    /**\n     * create command\n     *\n     * @return file name\n     * @throws Exception exception\n     */\n    public String buildCommand() throws Exception {\n        // generate scripts\n        String fileName = String.format(\"%s/%s_node.%s\",\n                taskExecutionContext.getExecutePath(),\n                taskExecutionContext.getTaskAppId(), SystemUtils.IS_OS_WINDOWS ? \"bat\" : \"sh\");\n\n        File file = new File(fileName);\n        Path path = file.toPath();\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java#L100-L136","documentation":"RemoteShellTask.cancel tries to kill the remote process via remoteExecutor.kill(taskId); any exception is wrapped into TaskException(\"cancel application error\"). Failure means the remote process may still be alive after a stop/timeout request.","triggerScenarios":"User stops the task or a timeout/fault-tolerance kill occurs and remoteExecutor.kill(taskId) throws — e.g., SSH session cannot be established to run the kill, or the remote pid no longer exists.","commonSituations":"Remote host unreachable during kill; task already completed so the pid is gone; SSH user lacks permission to kill the process; tracking file with the pid was deleted.","solutions":["Check the cause: 'no such process' means the task already ended and the kill failure is harmless.","Verify the worker can still SSH to the remote host to issue the kill command.","Confirm the SSH user owns or has rights to kill the remote process.","Manually kill the orphaned remote process (using the pid from logs) and verify no zombie processes remain."],"exampleFix":"// before\n} catch (Exception e) {\n    throw new TaskException(\"cancel application error\", e);\n}\n// after: tolerate already-finished remote process\n} catch (Exception e) {\n    log.warn(\"Failed to kill remote task {}; it may have already finished\", taskId, e);\n    throw new TaskException(\"cancel application error: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    remoteShellTask.cancel();\n} catch (TaskException e) {\n    if (e.getCause() != null && e.getCause().getMessage().contains(\"No such process\")) {\n        logger.info(\"Remote task already finished; kill unnecessary\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Treat kills of already-finished tasks as benign; alert only on SSH-unreachable kills.","Keep the pid tracking file intact until after kill/cleanup completes.","Ensure the SSH user can kill the processes it starts."],"tags":["task-cancel","remote-execution","process-kill","ssh"],"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"}