TechnitiumSoftware/DnsServer · error · DnsServerException

Failed to delete Secondary node: the Cluster is not initiali

Error message

Failed to delete Secondary node: the Cluster is not initialized.

What it means

Thrown by DeleteSecondaryNode when ClusterInitialized is false. Deleting a Secondary requires an active cluster with a node list from which to remove the target.

Source

Thrown at DnsServerCore/Cluster/ClusterManager.cs:767

                throw new DnsServerException("Failed to ask Secondary node to leave: only a Primary node can ask a Secondary node to leave the Cluster.");

            //find existing secondary node
            if (!_clusterNodes.TryGetValue(secondaryNodeId, out ClusterNode secondaryNode))
                throw new DnsServerException("Failed to ask Secondary node to leave: the specified node does not exist in the Cluster.");

            if (secondaryNode.Type == ClusterNodeType.Primary)
                throw new DnsServerException("Failed to ask Secondary node to leave: the specified node is the Cluster Primary node and cannot be removed.");

            //ask secondary node to leave the cluster
            await secondaryNode.AskSecondaryNodeToLeaveClusterAsync();

            return secondaryNode;
        }

        public ClusterNode DeleteSecondaryNode(int secondaryNodeId)
        {
            if (!ClusterInitialized)
                throw new DnsServerException("Failed to delete Secondary node: the Cluster is not initialized.");

            if (GetSelfNode().Type != ClusterNodeType.Primary)
                throw new DnsServerException("Failed to delete Secondary node: only a Primary node can delete a Secondary node from the Cluster.");

            //find existing secondary node
            IReadOnlyDictionary<int, ClusterNode> existingClusterNodes = _clusterNodes;

            if (!existingClusterNodes.TryGetValue(secondaryNodeId, out ClusterNode secondaryNode))
                throw new DnsServerException("Failed to delete Secondary node: the specified node does not exist in the Cluster.");

            if (secondaryNode.Type == ClusterNodeType.Primary)
                throw new DnsServerException("Failed to delete Secondary node: the specified node is the Cluster Primary node and cannot be deleted.");

            //delete secondary node from cluster nodes
            Dictionary<int, ClusterNode> updatedClusterNodes = new Dictionary<int, ClusterNode>(existingClusterNodes.Count - 1);

            foreach (KeyValuePair<int, ClusterNode> existingClusterNode in existingClusterNodes)
            {

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Check ClusterManager.ClusterInitialized before calling DeleteSecondaryNode.
  2. Ensure you are operating on the initialized Primary node.

Example fix

// before
_clusterManager.DeleteSecondaryNode(nodeId);
// after
if (!_clusterManager.ClusterInitialized)
    throw new InvalidOperationException("Cluster is not initialized.");
_clusterManager.DeleteSecondaryNode(nodeId);
Defensive patterns

Strategy: validation

Validate before calling

if (!_dnsWebService.ClusterManager.ClusterInitialized)
    throw new InvalidOperationException("Cluster is not initialized; cannot delete a Secondary node.");
_dnsWebService.ClusterManager.DeleteSecondaryNode(nodeId);

Type guard

static bool CanManageClusterNodes(ClusterManager cm) => cm.ClusterInitialized;

Try / catch

try
{
    _clusterManager.DeleteSecondaryNode(nodeId);
}
catch (DnsServerException ex) when (ex.Message.Contains("delete Secondary node") && ex.Message.Contains("not initialized"))
{
    // no cluster — nothing to delete
}

Prevention

When it happens

Trigger: DeleteSecondaryNode(secondaryNodeId) is called on a server where _clusterNodes is null or empty. The guard at line 766 fires before the node lookup.

Common situations: Calling delete-secondary on a non-clustered server; after the cluster was already torn down; on a Secondary that never joined.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/1e08a529be662b3d. Report an issue: GitHub.