{"record":{"id":"eeb61b2199d26285","repo":"apache/pulsar","slug":"resourcegroup-is-in-use","errorCode":null,"errorMessage":"ResourceGroup is in use","messagePattern":"ResourceGroup is in use","errorType":"http","errorClass":"RestException","httpStatus":412,"severity":"warning","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ResourceGroupsBase.java","lineNumber":192,"sourceCode":"                    .attr(\"resourceGroup\", rgName)\n                    .exceptionMessage(e)\n                    .log(\"Failed to get tenant/namespace list\");\n            throw new RestException(e);\n        }\n        return false;\n    }\n\n    protected void internalDeleteResourceGroup(String rgName) {\n        /*\n         * need to walk the namespaces and make sure it is not in use\n         */\n        try {\n            validateSuperUserAccess();\n            /*\n             * walk the namespaces and make sure it is not in use.\n             */\n            if (internalCheckRgInUse(rgName)) {\n                throw new RestException(Response.Status.PRECONDITION_FAILED, \"ResourceGroup is in use\");\n            }\n            resourceGroupResources().deleteResourceGroup(rgName);\n            log.info().attr(\"resourceGroup\", rgName).log(\"Deleted ResourceGroup\");\n        } catch (Exception e) {\n            log.error()\n                    .attr(\"resourceGroup\", rgName)\n                    .exception(e)\n                    .log(\"Failed to delete ResourceGroup .\");\n            throw new RestException(e);\n        }\n    }\n}\n","sourceCodeStart":174,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ResourceGroupsBase.java#L174-L205","documentation":"Returned with HTTP 412 PRECONDITION_FAILED when deleting a resource group that is still referenced by at least one tenant or namespace. internalDeleteResourceGroup calls internalCheckRgInUse first; if true it throws this RestException with 'ResourceGroup is in use' instead of deleting, protecting namespaces that still depend on the group's rate limits. It is an expected guard, not an infrastructure fault.","triggerScenarios":"DELETE /admin/v3/resourcegroups/{rgName} while any namespace policy still sets resourceGroup=rgName (e.g. via namespace publish/dispatch rate config referencing the group).","commonSituations":"Tearing down resource groups before migrating namespaces off them; forgotten namespace policies after offboarding an app; automation deleting groups referenced by templates.","solutions":["Find namespaces referencing the group (list tenants/namespaces and check their policies).","Update each namespace to remove or replace the resourceGroup reference.","Retry the delete once no namespaces reference the group.","If the reference is stale (namespace already deleted), clean up the leftover policy data and retry."],"exampleFix":"// before\nadmin.resourcegroups().deleteResourceGroup(rgName); // 412 if in use\n// after\ntry {\n    admin.resourcegroups().deleteResourceGroup(rgName);\n} catch (PulsarAdminException e) {\n    if (e.getStatusCode() == 412) {\n        namespaces.forEach(ns -> admin.namespaces().removeResourceGroup(ns)); // detach first\n        admin.resourcegroups().deleteResourceGroup(rgName);\n    } else { throw e; }\n}","handlingStrategy":"validation","validationCode":"// check references before deleting\nfor (String ns : listAllNamespaces(admin)) {\n    if (rgName.equals(getResourceGroupOf(ns))) throw new IllegalStateException(ns + \" still uses \" + rgName);\n}","typeGuard":"null","tryCatchPattern":"try {\n    admin.resourcegroups().deleteResourceGroup(rgName);\n} catch (PulsarAdminException e) {\n    if (e.getStatusCode() == 412) detachFromAllNamespaces(rgName); // then retry\n    else throw e;\n}","preventionTips":["Migrate namespaces off a resource group before deleting it.","Automate a reference scan as part of teardown runbooks.","Treat 412 as expected flow control, not an error condition."],"tags":["rest-api","precondition-failed","resourcegroups","delete-guard"],"backgroundTag":"resource-in-use","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}