{"record":{"id":"5f10742dd9c9e47e","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-delete-cluster-the-cluster-is-not-initi","errorCode":null,"errorMessage":"Failed to delete Cluster: the Cluster is not initialized.","messagePattern":"Failed to delete Cluster: the Cluster is not initialized\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Cluster/ClusterManager.cs","lineNumber":672,"sourceCode":"            RemoveAllClusterPrimaryZoneNSRecords(); //remove all existing NS records\n            AddClusterPrimaryZoneRecordsFor(selfPrimaryNode, nsTtl, aTtl, _dnsWebService.WebServiceTlsCertificate);\n\n            //update cluster catalog zone ACLs, TSIG key name and save zone file\n            UpdateClusterCatalogZoneOptions(clusterCatalogZoneInfo);\n\n            //finalize\n            _dnsWebService.DnsServer.ServerDomain = selfPrimaryNode.Name;\n\n            //save all changes\n            _dnsWebService.DnsServer.SaveConfigFile(true);\n            _dnsWebService.AuthManager.SaveConfigFile(true);\n            SaveConfigFile();\n        }\n\n        public void DeleteCluster(bool forceDelete)\n        {\n            if (!ClusterInitialized)\n                throw new DnsServerException(\"Failed to delete Cluster: the Cluster is not initialized.\");\n\n            if (GetSelfNode().Type != ClusterNodeType.Primary)\n                throw new DnsServerException(\"Failed to delete Cluster: only a Primary node can delete the Cluster.\");\n\n            if (!forceDelete && (_clusterNodes.Count > 1))\n                throw new DnsServerException(\"Failed to delete Cluster: please remove all Secondary nodes before deleting the Cluster.\");\n\n            DeleteAllClusterConfig();\n        }\n\n        public ClusterNode JoinCluster(int secondaryNodeId, Uri secondaryNodeUrl, IReadOnlyList<IPAddress> secondaryNodeIpAddresses, X509Certificate2 secondaryNodeCertificate)\n        {\n            if (!ClusterInitialized)\n                throw new DnsServerException(\"Failed to add Secondary node: the Cluster is not initialized.\");\n\n            if (GetSelfNode().Type != ClusterNodeType.Primary)\n                throw new DnsServerException(\"Failed to add Secondary node: only a Primary node can add a Secondary node to the Cluster.\");\n","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Cluster/ClusterManager.cs#L654-L690","documentation":"Thrown by DeleteCluster when ClusterInitialized is false. ClusterInitialized returns true only when _clusterNodes is non-null and contains at least one node (line 2199-2207). You cannot delete a cluster that was never created or has already been removed.","triggerScenarios":"DeleteCluster(forceDelete) is called on a server where _clusterNodes is null or empty — either no cluster was ever initialized, or a prior DeleteCluster already cleared the node list.","commonSituations":"Calling DeleteCluster twice (double-delete); calling it on a fresh server that was never clustered; calling it on a Secondary node that lost its config; UI allowing a delete button click when no cluster is active.","solutions":["Check ClusterManager.ClusterInitialized before calling DeleteCluster.","Confirm you are operating on the correct server instance that actually hosts the cluster Primary node.","If the cluster was already deleted, no further action is needed."],"exampleFix":"// before\n_dnsWebService.ClusterManager.DeleteCluster(false);\n// after\nif (_dnsWebService.ClusterManager.ClusterInitialized)\n    _dnsWebService.ClusterManager.DeleteCluster(false);","handlingStrategy":"validation","validationCode":"if (!_dnsWebService.ClusterManager.ClusterInitialized)\n    return; // or inform the user no cluster exists\n_dnsWebService.ClusterManager.DeleteCluster(false);","typeGuard":"static bool CanDeleteCluster(ClusterManager cm) => cm.ClusterInitialized;","tryCatchPattern":"try\n{\n    _dnsWebService.ClusterManager.DeleteCluster(false);\n}\ncatch (DnsServerException ex) when (ex.Message.Contains(\"the Cluster is not initialized\"))\n{\n    // no cluster to delete — treat as no-op\n}","preventionTips":["Check ClusterInitialized before calling DeleteCluster.","Disable or hide the delete-cluster UI control when no cluster is active.","Track cluster state in your orchestration layer to avoid double-delete calls."],"tags":["cluster","lifecycle","delete","validation","not-initialized"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}