{"record":{"id":"5a7210149197de3e","repo":"apache/dolphinscheduler","slug":"10145","errorCode":"10145","errorMessage":"delete worker group by id fail, for there are {0} workflow instances in executing using it","messagePattern":"delete worker group by id fail, for there are (.+?) workflow instances in executing using it","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java","lineNumber":333,"sourceCode":"    public void deleteWorkerGroupById(User loginUser, Integer id) {\n        if (!canOperatorPermissions(loginUser, null, AuthorizationType.WORKER_GROUP, WORKER_GROUP_DELETE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n        WorkerGroup workerGroup = workerGroupDao.queryById(id);\n        if (workerGroup == null) {\n            log.error(\"Worker group does not exist, workerGroupId:{}.\", id);\n            throw new ServiceException(Status.DELETE_WORKER_GROUP_NOT_EXIST);\n        }\n        List<WorkflowInstanceSummaryDto> workflowInstances = workflowInstanceDao.queryByWorkerGroupNameAndStatus(\n                workerGroup.getName(),\n                WorkflowExecutionStatus.NOT_TERMINAL_STATES);\n        if (CollectionUtils.isNotEmpty(workflowInstances)) {\n            List<Integer> workflowInstanceIds =\n                    workflowInstances.stream().map(WorkflowInstanceSummaryDto::getId).collect(Collectors.toList());\n            log.warn(\n                    \"Delete worker group failed because there are {} workflowInstances are using it, workflowInstanceIds:{}.\",\n                    workflowInstances.size(), workflowInstanceIds);\n            throw new ServiceException(Status.DELETE_WORKER_GROUP_BY_ID_FAIL, workflowInstances.size());\n        }\n\n        checkWorkerGroupDependencies(workerGroup);\n\n        workerGroupDao.deleteById(id);\n        boardCastToMasterThatWorkerGroupChanged();\n\n        log.info(\"Delete worker group complete, workerGroupName:{}.\", workerGroup.getName());\n    }\n\n    /**\n     * query all worker address list\n     *\n     * @return all worker address set\n     */\n    @Override\n    public Set<String> getWorkerAddressList() {\n        return registryClient.getServerNodeSet(RegistryNodeType.WORKER);","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java#L315-L351","documentation":"Thrown in deleteWorkerGroupById when queryByWorkerGroupNameAndStatus finds non-terminal (running/pending) workflow instances whose workflow instance still uses this worker group. Deletion is blocked because live instances depend on it; the message reports how many.","triggerScenarios":"Calling DELETE /worker-groups/{id} while at least one workflow instance in a NOT_TERMINAL state (e.g. RUNNING_EXECUTION, WAITING) was scheduled/executed with the group's name.","commonSituations":"Deleting a worker group while long-running or scheduled workflows are still active; a stuck non-terminal instance blocks deletion even though nothing is really running; deleting during peak scheduler usage.","solutions":["Wait for running workflow instances to finish or stop/kill them, then delete the worker group.","Reassign the affected workflow/schedule definitions to another worker group and let old instances terminate.","If instances are stale/leaked, fix their state (or let them time out) so no NOT_TERMINAL instances reference the group, then retry."],"exampleFix":"// before\nworkerGroupService.deleteWorkerGroupById(loginUser, id); // 10145 while jobs run\n// after: stop running instances first\nworkflowInstances using the group -> stop/kill via UI or API\nworkerGroupService.deleteWorkerGroupById(loginUser, id); // succeeds","handlingStrategy":"validation","validationCode":"List<WorkflowInstanceSummaryDto> active = workflowInstanceDao\n    .queryByWorkerGroupNameAndStatus(groupName, WorkflowExecutionStatus.NOT_TERMINAL_STATES);\nboolean deletable = active.isEmpty();","typeGuard":null,"tryCatchPattern":"try {\n    workerGroupService.deleteWorkerGroupById(loginUser, id);\n} catch (ServiceException e) {\n    if (e.getCode() == 10145) { /* stop/wait running instances, retry */ }\n    else throw e;\n}","preventionTips":["Schedule worker-group retirement for windows with no active or scheduled workflows using the group.","Migrate workflow schedules to a new group and drain old instances before deleting.","Monitor for leaked non-terminal instances that permanently block deletion."],"tags":["worker-group","workflow-instance","dependency-check","delete"],"backgroundTag":"invalid-state-transition","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"}