{"record":{"id":"1e08a529be662b3d","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-delete-secondary-node-the-cluster-is-no","errorCode":null,"errorMessage":"Failed to delete Secondary node: the Cluster is not initialized.","messagePattern":"Failed to delete Secondary node: the Cluster is not initialized\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Cluster/ClusterManager.cs","lineNumber":767,"sourceCode":"                throw new DnsServerException(\"Failed to ask Secondary node to leave: only a Primary node can ask a Secondary node to leave the Cluster.\");\n\n            //find existing secondary node\n            if (!_clusterNodes.TryGetValue(secondaryNodeId, out ClusterNode secondaryNode))\n                throw new DnsServerException(\"Failed to ask Secondary node to leave: the specified node does not exist in the Cluster.\");\n\n            if (secondaryNode.Type == ClusterNodeType.Primary)\n                throw new DnsServerException(\"Failed to ask Secondary node to leave: the specified node is the Cluster Primary node and cannot be removed.\");\n\n            //ask secondary node to leave the cluster\n            await secondaryNode.AskSecondaryNodeToLeaveClusterAsync();\n\n            return secondaryNode;\n        }\n\n        public ClusterNode DeleteSecondaryNode(int secondaryNodeId)\n        {\n            if (!ClusterInitialized)\n                throw new DnsServerException(\"Failed to delete Secondary node: the Cluster is not initialized.\");\n\n            if (GetSelfNode().Type != ClusterNodeType.Primary)\n                throw new DnsServerException(\"Failed to delete Secondary node: only a Primary node can delete a Secondary node from the Cluster.\");\n\n            //find existing secondary node\n            IReadOnlyDictionary<int, ClusterNode> existingClusterNodes = _clusterNodes;\n\n            if (!existingClusterNodes.TryGetValue(secondaryNodeId, out ClusterNode secondaryNode))\n                throw new DnsServerException(\"Failed to delete Secondary node: the specified node does not exist in the Cluster.\");\n\n            if (secondaryNode.Type == ClusterNodeType.Primary)\n                throw new DnsServerException(\"Failed to delete Secondary node: the specified node is the Cluster Primary node and cannot be deleted.\");\n\n            //delete secondary node from cluster nodes\n            Dictionary<int, ClusterNode> updatedClusterNodes = new Dictionary<int, ClusterNode>(existingClusterNodes.Count - 1);\n\n            foreach (KeyValuePair<int, ClusterNode> existingClusterNode in existingClusterNodes)\n            {","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Cluster/ClusterManager.cs#L749-L785","documentation":"Thrown by DeleteSecondaryNode when ClusterInitialized is false. Deleting a Secondary requires an active cluster with a node list from which to remove the target.","triggerScenarios":"DeleteSecondaryNode(secondaryNodeId) is called on a server where _clusterNodes is null or empty. The guard at line 766 fires before the node lookup.","commonSituations":"Calling delete-secondary on a non-clustered server; after the cluster was already torn down; on a Secondary that never joined.","solutions":["Check ClusterManager.ClusterInitialized before calling DeleteSecondaryNode.","Ensure you are operating on the initialized Primary node."],"exampleFix":"// before\n_clusterManager.DeleteSecondaryNode(nodeId);\n// after\nif (!_clusterManager.ClusterInitialized)\n    throw new InvalidOperationException(\"Cluster is not initialized.\");\n_clusterManager.DeleteSecondaryNode(nodeId);","handlingStrategy":"validation","validationCode":"if (!_dnsWebService.ClusterManager.ClusterInitialized)\n    throw new InvalidOperationException(\"Cluster is not initialized; cannot delete a Secondary node.\");\n_dnsWebService.ClusterManager.DeleteSecondaryNode(nodeId);","typeGuard":"static bool CanManageClusterNodes(ClusterManager cm) => cm.ClusterInitialized;","tryCatchPattern":"try\n{\n    _clusterManager.DeleteSecondaryNode(nodeId);\n}\ncatch (DnsServerException ex) when (ex.Message.Contains(\"delete Secondary node\") && ex.Message.Contains(\"not initialized\"))\n{\n    // no cluster — nothing to delete\n}","preventionTips":["Check ClusterInitialized before calling DeleteSecondaryNode.","Disable delete-secondary controls when no cluster is active.","Ensure the operation targets the initialized Primary."],"tags":["cluster","delete-secondary","validation","not-initialized"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}