{"record":{"id":"e29864977259b1ff","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-initialize-cluster-the-cluster-is-alrea","errorCode":null,"errorMessage":"Failed to initialize Cluster: the Cluster is already initialized.","messagePattern":"Failed to initialize Cluster: the Cluster is already initialized\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Cluster/ClusterManager.cs","lineNumber":523,"sourceCode":"            //finalize\n            if (_dnsWebService.DnsServer.ServerDomain.EndsWith(\".\" + _clusterDomain, StringComparison.OrdinalIgnoreCase))\n                _dnsWebService.DnsServer.ServerDomain = _dnsWebService.DnsServer.ServerDomain.Substring(0, _dnsWebService.DnsServer.ServerDomain.Length - (_clusterDomain.Length + 1));\n\n            //save all changes\n            _dnsWebService.DnsServer.SaveConfigFile();\n            _dnsWebService.AuthManager.SaveConfigFile();\n\n            UnloadAndDeleteConfigFile();\n        }\n\n        #endregion\n\n        #region primary node\n\n        public void InitializeCluster(string clusterDomain, IReadOnlyList<IPAddress> primaryNodeIpAddresses, UserSession session)\n        {\n            if (ClusterInitialized)\n                throw new DnsServerException(\"Failed to initialize Cluster: the Cluster is already initialized.\");\n\n            if (!_dnsWebService.IsWebServiceTlsEnabled)\n                throw new InvalidOperationException();\n\n            if (session.User.IsSsoUser)\n                throw new DnsServerException(\"Failed to initialize Cluster: a SSO user cannot initialize cluster. Please login with a local administrator user account and try again.\");\n\n            clusterDomain = clusterDomain.ToLowerInvariant();\n\n            //create self node\n            string serverDomain = _dnsWebService.DnsServer.ServerDomain;\n            if (!serverDomain.EndsWith(\".\" + clusterDomain, StringComparison.OrdinalIgnoreCase))\n            {\n                int x = serverDomain.IndexOf('.');\n                if (x < 0)\n                    serverDomain = serverDomain + \".\" + clusterDomain;\n                else\n                    serverDomain = string.Concat(serverDomain.AsSpan(0, x), \".\", clusterDomain);","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Cluster/ClusterManager.cs#L505-L541","documentation":"Thrown by ClusterManager.InitializeCluster when the ClusterInitialized property is already true, meaning a cluster config (clusterDomain + clusterNodes) already exists on this node. InitializeCluster is a one-time bootstrap; calling it again would orphan the existing cluster zone, catalog zone, and node topology, so it is rejected up front before any state is touched.","triggerScenarios":"Invoking InitializeCluster a second time on a node that has already been clustered — e.g. an admin retries the setup wizard, or automation calls the cluster-init API on an already-initialized node.","commonSituations":"Re-running a provisioning script idempotently without checking cluster state; the UI does not hide the 'initialize cluster' button once a cluster exists; an aborted first attempt that actually completed.","solutions":["Check ClusterInitialized before calling InitializeCluster and skip or guide the admin to 'add node' instead.","To re-initialize, first delete/leave the existing cluster and clear the cluster config.","Hide the initialize action in the UI once a cluster is present."],"exampleFix":"// before\nclusterManager.InitializeCluster(domain, ips, session);\n\n// after\nif (!clusterManager.ClusterInitialized)\n    clusterManager.InitializeCluster(domain, ips, session);","handlingStrategy":"validation","validationCode":"if (clusterManager.ClusterInitialized)\n    return Conflict(\"Cluster is already initialized; use 'add node' instead.\");\nclusterManager.InitializeCluster(domain, ips, session);","typeGuard":"static bool CanInitializeCluster(ClusterManager cm) => !cm.ClusterInitialized;","tryCatchPattern":null,"preventionTips":["Check ClusterInitialized before calling InitializeCluster.","Hide the initialize action in the UI once a cluster exists.","Make provisioning scripts idempotent by skipping an already-initialized cluster."],"tags":["cluster","state","initialization","technitium-dns-server"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}