{"record":{"id":"9c2ae227ff3fb51c","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-promote-to-primary-node-the-cluster-is","errorCode":null,"errorMessage":"Failed to promote to Primary node: the Cluster is not initialized.","messagePattern":"Failed to promote to Primary node: the Cluster is not initialized\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Cluster/ClusterManager.cs","lineNumber":1940,"sourceCode":"                UpdateConfigRefreshTimer(_configRefreshIntervalSeconds * 1000); //apply new interval to config refresh timer immediately\n                saveConfig = true;\n            }\n\n            if (primaryNodeClusterInfo.ConfigRetryIntervalSeconds != _configRetryIntervalSeconds)\n            {\n                _configRetryIntervalSeconds = primaryNodeClusterInfo.ConfigRetryIntervalSeconds;\n                saveConfig = true;\n            }\n\n            //save changes\n            if (saveConfig)\n                SaveConfigFile();\n        }\n\n        public async Task PromoteToPrimaryNodeAsync(bool forceDeletePrimary)\n        {\n            if (!ClusterInitialized)\n                throw new DnsServerException(\"Failed to promote to Primary node: the Cluster is not initialized.\");\n\n            //do validation\n            ClusterNode selfNewPrimaryNode = GetSelfNode();\n            if (selfNewPrimaryNode.Type != ClusterNodeType.Secondary)\n                throw new DnsServerException(\"Failed to promote to Primary node: only Secondary nodes can be promoted to Primary nodes.\");\n\n            string clusterCatalogDomain = \"cluster-catalog.\" + _clusterDomain;\n\n            AuthZoneInfo clusterCatalogZoneInfo = _dnsWebService.DnsServer.AuthZoneManager.GetAuthZoneInfo(clusterCatalogDomain);\n            if (clusterCatalogZoneInfo is null)\n                throw new DnsServerException(\"Failed to promote to Primary node: the Cluster Secondary Catalog zone does not exist.\");\n\n            AuthZoneInfo clusterZoneInfo = _dnsWebService.DnsServer.AuthZoneManager.GetAuthZoneInfo(_clusterDomain);\n            if (clusterZoneInfo is null)\n                throw new DnsServerException(\"Failed to promote to Primary node: the Cluster Secondary zone does not exist.\");\n\n            //stop cluster config refresh timer\n            StopConfigRefreshTimer();","sourceCodeStart":1922,"sourceCodeEnd":1958,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Cluster/ClusterManager.cs#L1922-L1958","documentation":"Thrown at the top of PromoteToPrimaryNodeAsync when ClusterInitialized is false. Promotion turns the local secondary into the cluster primary, which requires an existing cluster with a current primary to replace; a standalone node has nothing to promote within.","triggerScenarios":"Calling PromoteToPrimaryNodeAsync on a server that is not part of any cluster.","commonSituations":"Operator clicked 'promote to primary' on a standalone box; the node already left the cluster; cluster config cleared between page load and the action.","solutions":["Guard on ClusterInitialized; report 'not clustered' instead of promoting.","If clustering is intended, JoinClusterAsync as a secondary first, then promote.","Hide the promote action when the node is not clustered or not a secondary."],"exampleFix":"// before\nawait clusterManager.PromoteToPrimaryNodeAsync(forceDeletePrimary: false);\n\n// after\nif (!clusterManager.ClusterInitialized)\n    return BadRequest(\"Not clustered; cannot promote.\");\nawait clusterManager.PromoteToPrimaryNodeAsync(forceDeletePrimary: false);","handlingStrategy":"validation","validationCode":"if (!clusterManager.ClusterInitialized)\n    return BadRequest(\"Not clustered; cannot promote.\");\nawait clusterManager.PromoteToPrimaryNodeAsync(forceDeletePrimary: false);","typeGuard":"static bool CanPromote(ClusterManager cm) => cm.ClusterInitialized;","tryCatchPattern":"try { await clusterManager.PromoteToPrimaryNodeAsync(false); }\ncatch (DnsServerException ex) when (ex.Message.Contains(\"not initialized\"))\n{ /* join a cluster first, then promote */ }","preventionTips":["Only offer 'promote to primary' on clustered secondary nodes.","Gate the call on ClusterInitialized and on GetSelfNode().Type == Secondary.","Join as a secondary before attempting promotion."],"tags":["cluster","precondition","promote","technitium","state-guard"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}