{"record":{"id":"ed02d8f86a79ccde","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-update-secondary-node-the-specified-nod-ed02d8","errorCode":null,"errorMessage":"Failed to update Secondary node: the specified node to update must be a Secondary node.","messagePattern":"Failed to update Secondary node: the specified node to update must be a Secondary node\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Cluster/ClusterManager.cs","lineNumber":830,"sourceCode":"\n            return secondaryNode;\n        }\n\n        public ClusterNode UpdateSecondaryNode(int secondaryNodeId, Uri secondaryNodeUrl, IReadOnlyList<IPAddress> secondaryNodeIpAddresses, X509Certificate2 secondaryNodeCertificate)\n        {\n            if (!ClusterInitialized)\n                throw new DnsServerException(\"Failed to update Secondary node: the Cluster is not initialized.\");\n\n            if (GetSelfNode().Type != ClusterNodeType.Primary)\n                throw new DnsServerException(\"Failed to update Secondary node: only a Primary node can update a Secondary node's details in the Cluster.\");\n\n            IReadOnlyDictionary<int, ClusterNode> clusterNodes = _clusterNodes;\n\n            if (!clusterNodes.TryGetValue(secondaryNodeId, out ClusterNode secondaryNode))\n                throw new DnsServerException(\"Failed to update Secondary node: the specified node does not exist in the Cluster.\");\n\n            if (secondaryNode.Type != ClusterNodeType.Secondary)\n                throw new DnsServerException(\"Failed to update Secondary node: the specified node to update must be a Secondary node.\");\n\n            //validate for duplicate names\n            foreach (KeyValuePair<int, ClusterNode> clusterNode in clusterNodes)\n            {\n                if (clusterNode.Key == secondaryNodeId)\n                    continue; //skip self\n\n                if (clusterNode.Value.Name.Equals(secondaryNodeUrl.Host, StringComparison.OrdinalIgnoreCase))\n                    throw new DnsServerException(\"Failed to update Secondary node: A node with the same DNS Server Domain Name already exists in the Cluster. Please try again after changing the Secondary node's DNS Server Domain Name.\");\n            }\n\n            bool secondaryNodeDomainChanged = !secondaryNode.Name.Equals(secondaryNodeUrl.Host, StringComparison.OrdinalIgnoreCase);\n\n            //find existing record TTL values\n            FindExistingRecordTtlValues(out uint nsTtl, out uint aTtl);\n\n            //update cluster zone to remove existing records for secondary node\n            RemoveClusterPrimaryZoneRecordsFor(secondaryNode);","sourceCodeStart":812,"sourceCodeEnd":848,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Cluster/ClusterManager.cs#L812-L848","documentation":"UpdateSecondaryNode found the node by ID, but its Type is not Secondary (it is the Primary). Only Secondary nodes are valid targets for this update; the Primary's identity is managed separately.","triggerScenarios":"Passing the Primary node's ID into UpdateSecondaryNode; a node whose role changed from Secondary to Primary after the caller cached it.","commonSituations":"Promotion or demotion flipping a node's role; a UI reusing a selected node across a role change; treating the self/Primary ID as editable.","solutions":["Target a node whose Type is Secondary","Refresh cluster state to learn current roles before editing","Re-select the node after any topology change"],"exampleFix":"// before\nclusterManager.UpdateSecondaryNode(primaryId, url, ips, cert);\n\n// after\nvar node = clusterNodes.First(n => n.Id == id);\nif (node.Type != ClusterNodeType.Secondary)\n    throw new InvalidOperationException(\"Pick a Secondary node to update.\");\nclusterManager.UpdateSecondaryNode(id, url, ips, cert);","handlingStrategy":"validation","validationCode":"var node = clusterState.ClusterNodes.FirstOrDefault(n => n.Id == id);\nif (node is null || node.Type != ClusterNodeType.Secondary)\n    return BadRequest(\"Select a Secondary node.\");\nclusterManager.UpdateSecondaryNode(id, url, ips, cert);","typeGuard":null,"tryCatchPattern":"catch (DnsServerException ex) when (ex.Message.Contains(\"must be a Secondary node\"))\n{ /* refresh roles and let user re-pick */ }","preventionTips":["Filter the editable node list to Secondary before presenting it","Refresh node roles after any promotion or demotion"],"tags":["cluster","primary-node","validation","dns-server"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}