apache/dolphinscheduler · error · TaskExecutionContextCreateException

TaskExecutionContextCreateException(ex.getMessage())

Error message

TaskExecutionContextCreateException(ex.getMessage())

What it means

Wraps any non-database exception raised while initializing a task's TaskExecutionContext during dispatch. The master aborts dispatching the task to the worker and raises TaskExecutionContextCreateException carrying the original message. DB connectivity failures are rethrown as-is instead.

Source

Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/statemachine/TaskSubmittedStateAction.java:122

                taskInstance.getFirstSubmitTime(),
                taskInstance.getDelayTime() * 60L) * 1_000;
        if (remainTimeMills > 0) {
            taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION);
            taskInstanceDao.updateById(taskInstance);
            log.info("Current taskInstance: {} is choose delay execution, delay time: {}/min, remainTime: {}/ms",
                    taskInstance.getName(),
                    taskInstance.getDelayTime(),
                    remainTimeMills);
        }

        try {
            taskExecution.initializeTaskExecutionContext();
        } catch (Exception ex) {
            if (ExceptionUtils.isDatabaseConnectedFailedException(ex)) {
                throw ex;
            }
            log.error("Failed to initialize task execution context, taskName: {}", taskInstance.getName(), ex);
            throw new TaskExecutionContextCreateException(ex.getMessage());
        }

        workerGroupDispatcherCoordinator.dispatchTask(taskExecution, remainTimeMills);
    }

    @Override
    public void onDispatchedEvent(final IWorkflowExecution workflowExecution,
                                  final ITaskExecution taskExecution,
                                  final TaskDispatchedLifecycleEvent taskDispatchedEvent) {
        throwExceptionIfStateIsNotMatch(taskExecution);
        super.onDispatchedEvent(workflowExecution, taskExecution, taskDispatchedEvent);
    }

    @Override
    public void onPauseEvent(final IWorkflowExecution workflowExecution,
                             final ITaskExecution taskExecution,
                             final TaskPauseLifecycleEvent taskPauseEvent) {
        throwExceptionIfStateIsNotMatch(taskExecution);

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Read the wrapped cause message to identify the initialization failure
  2. Fix the task definition parameters or plugin configuration
  3. Verify DB-related failures are surfaced as the original exception (they bypass this wrapper)
  4. Retry the workflow instance after correcting the task config

Example fix

// before
throw new TaskExecutionContextCreateException(ex.getMessage()); // loses stack
// after
throw new TaskExecutionContextCreateException("init failed for task " + taskInstance.getName(), ex);
Defensive patterns

Strategy: try-catch

Validate before calling

// validate task params before submit
if (taskInstance.getTaskParams() == null || taskInstance.getTaskParams().isEmpty()) throw new IllegalArgumentException("empty taskParams");

Try / catch

try { dispatch(taskExecution); } catch (TaskExecutionContextCreateException e) { log.error("context init failed: {}", e.getMessage(), e); markTaskFailed(taskInstance); }

Prevention

When it happens

Trigger: taskExecution.initializeTaskExecutionContext() fails due to bad task parameters, missing resource/plugin config, or any non-DB exception during onDispatchEvent of TaskSubmittedStateAction.

Common situations: Misconfigured task plugins, corrupt task instance parameters in DB, missing JARs/resources needed to build the execution context.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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