apache/dolphinscheduler · error · ServiceException

DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL

DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL

Error message

DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL: can not be deleted because there are {0} executing instances

What it means

Thrown when the workflow definition still has non-terminal workflow instances (running, waiting, etc.). The service queries workflowInstanceService.queryByWorkflowDefinitionCodeAndStatus with NOT_TERMINAL_STATES and refuses deletion while executions are in flight, reporting the instance count in the message.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:857

    /**
     * workflow definition want to delete whether used in other task, should throw exception when have be used.
     * <p>
     * This function avoid delete workflow definition already dependencies by other tasks by accident.
     *
     * @param workflowDefinition WorkflowDefinition you change task definition and task relation
     */
    private void workflowDefinitionUsedInOtherTaskValid(User loginUser, WorkflowDefinition workflowDefinition) {
        // check workflow definition is already online
        if (workflowDefinition.getReleaseState() == ReleaseState.ONLINE) {
            throw new ServiceException(Status.WORKFLOW_DEFINE_STATE_ONLINE, workflowDefinition.getName());
        }

        // check workflow instances is already running
        List<WorkflowInstanceSummaryDto> workflowInstances =
                workflowInstanceService.queryByWorkflowDefinitionCodeAndStatus(
                        workflowDefinition.getCode(), WorkflowExecutionStatus.NOT_TERMINAL_STATES);
        if (CollectionUtils.isNotEmpty(workflowInstances)) {
            throw new ServiceException(Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL, workflowInstances.size());
        }

        // check workflow used by other task, including sub workflow and dependent task type
        Optional<String> taskDepMsg = workflowLineageService.taskDependentMsg(loginUser,
                workflowDefinition.getProjectCode(), workflowDefinition.getCode(), 0);

        if (taskDepMsg.isPresent()) {
            String errorMeg = "workflow definition cannot be deleted because it has dependent, " + taskDepMsg.get();
            log.error(errorMeg);
            throw new ServiceException(errorMeg);
        }
    }

    public void deleteWorkflowDefinitionByCode(User loginUser, long code) {
        WorkflowDefinition workflowDefinition = workflowDefinitionDao.queryByCode(code)
                .orElseThrow(() -> new ServiceException(WORKFLOW_DEFINITION_NOT_EXIST, String.valueOf(code)));

        Project project = projectDao.queryByCode(workflowDefinition.getProjectCode());

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Wait for the running instances to finish, then delete.
  2. Force-stop or kill the executing instances via the workflow-instance API, then retry deletion.
  3. For zombie instances, correct their state to a terminal value (admin action) and delete again.

Example fix

// before
workflowDefinitionService.deleteWorkflowDefinitionByCode(loginUser, code); // instances running
// after
List<WorkflowInstanceSummaryDto> running = workflowInstanceService
    .queryByWorkflowDefinitionCodeAndStatus(code, WorkflowExecutionStatus.NOT_TERMINAL_STATES);
running.forEach(i -> workflowInstanceService.forceStop(i.getId(), loginUser));
workflowDefinitionService.deleteWorkflowDefinitionByCode(loginUser, code);
Defensive patterns

Strategy: validation

Validate before calling

List<WorkflowInstanceSummaryDto> running = workflowInstanceService
    .queryByWorkflowDefinitionCodeAndStatus(code, WorkflowExecutionStatus.NOT_TERMINAL_STATES);
if (!running.isEmpty()) {
    running.forEach(i -> workflowInstanceService.forceStop(i.getId(), user));
}

Try / catch

try { service.deleteWorkflowDefinitionByCode(user, code); }
catch (ServiceException e) { if (e.getCode() == Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL) { /* stop instances then retry */ } }

Prevention

When it happens

Trigger: Deleting a workflow whose scheduler kicked off instances still executing, or manually-started runs that have not finished (or are stuck in a non-terminal state).

Common situations: Deleting during a long-running ETL workflow; stuck/zombie instances left in RUNNING state after a master crash; deleting a workflow right after triggering it in a test.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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