apache/dolphinscheduler · error · TaskException

cancel application error

Error message

cancel application error

What it means

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.

Source

Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java:107

            setExitStatusCode(taskResponse.getExitStatusCode());
            setProcessId(taskResponse.getProcessId());
            setTaskOutputParams(shellCommandExecutor.getTaskOutputParams());
            pythonParameters.dealOutParam(shellCommandExecutor.getTaskOutputParams());
            taskRequest.setVarPool(pythonParameters.getVarPool());
        } catch (Exception e) {
            log.error("python task failure", e);
            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
            throw new TaskException("run python task error", e);
        }
    }

    @Override
    public void cancel() throws TaskException {
        // cancel process
        try {
            shellCommandExecutor.cancelApplication();
        } catch (Exception e) {
            throw new TaskException("cancel application error", e);
        }
    }

    @Override
    public AbstractParameters getParameters() {
        return pythonParameters;
    }

    /**
     * create python command file if not exists
     *
     * @param pythonScript     exec python script
     * @param pythonScriptFile python script file
     * @throws IOException io exception
     */
    protected void createPythonCommandFileIfNotExists(String pythonScript, String pythonScriptFile) throws IOException {
        log.info("tenantCode :{}, task dir:{}", taskRequest.getTenantCode(), taskRequest.getExecutePath());

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Check the cause: if the process already terminated, the cancel failure is benign and can be ignored.
  2. Verify the worker user has permission to kill the task's child processes (same OS user as the executing task).
  3. Inspect shellCommandExecutor/kill command logs for the pid used and any OS-level kill errors.
  4. Retry cancel if it failed transiently (e.g., InterruptedException during process wait).

Example fix

// before
} catch (Exception e) {
    throw new TaskException("cancel application error", e);
}
// after: tolerate already-dead process
} catch (Exception e) {
    log.warn("cancel python task failed, process may have already exited", e);
    throw new TaskException("cancel application error: " + e.getMessage(), e);
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    pythonTask.cancel();
} catch (TaskException e) {
    // treat 'process already exited' as benign
    logger.warn("Cancel failed (task may have completed): {}", e.getMessage());
}

Prevention

When it happens

Trigger: 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.

Common situations: Stopping a task that already finished (race between completion and kill); worker process table issues; permissions preventing pkill/kill of the child process.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/d6de3d80246bd7c4. Report an issue: GitHub.