{"record":{"id":"e2caced537c44cc5","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-join-cluster-the-cluster-is-already-ini","errorCode":null,"errorMessage":"Failed to join Cluster: the Cluster is already initialized.","messagePattern":"Failed to join Cluster: the Cluster is already initialized\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Cluster/ClusterManager.cs","lineNumber":1328,"sourceCode":"            }\n            catch (Exception ex)\n            {\n                _dnsWebService.LogManager.Write(ex);\n            }\n            finally\n            {\n                _notifyAllSecondaryNodesTimerTriggered = false;\n            }\n        }\n\n        #endregion\n\n        #region secondary node\n\n        public async Task InitializeAndJoinClusterAsync(IReadOnlyList<IPAddress> secondaryNodeIpAddresses, Uri primaryNodeUrl, string primaryNodeUsername, string primaryNodePassword, string primaryNodeTotp = null, IReadOnlyList<IPAddress> primaryNodeIpAddresses = null, bool ignoreCertificateErrors = false, CancellationToken cancellationToken = default)\n        {\n            if (ClusterInitialized)\n                throw new DnsServerException(\"Failed to join Cluster: the Cluster is already initialized.\");\n\n            if (!_dnsWebService.IsWebServiceTlsEnabled)\n                throw new InvalidOperationException();\n\n            if (IPAddress.TryParse(primaryNodeUrl.Host, out _))\n                throw new DnsServerException(\"Failed to join Cluster: the Primary Node URL must use the domain name of the Primary node and not its IP address.\");\n\n            if (primaryNodeIpAddresses is null)\n            {\n                try\n                {\n                    IReadOnlyList<IPAddress> ipAddresses = await DnsClient.ResolveIPAsync(_dnsWebService.DnsServer, primaryNodeUrl.Host, _dnsWebService.DnsServer.IPv6Mode, cancellationToken);\n                    if (ipAddresses.Count < 1)\n                        throw new DnsServerException($\"Failed to join Cluster: the domain name '{primaryNodeUrl.Host}' does not have an A/AAAA record configured.\");\n\n                    primaryNodeIpAddresses = ipAddresses;\n                }\n                catch (Exception ex)","sourceCodeStart":1310,"sourceCodeEnd":1346,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Cluster/ClusterManager.cs#L1310-L1346","documentation":"InitializeAndJoinClusterAsync refuses because this node already belongs to a cluster (ClusterInitialized is true). A node can join only once; to rejoin it must leave or reset first.","triggerScenarios":"Calling join on a node that is already a Primary or Secondary; double-clicking 'join cluster'; retrying join after a partial success.","commonSituations":"Operator forgetting the node is already clustered; automation re-running join idempotently without checking; a recovered node that still has cluster state.","solutions":["Leave the current cluster / reset cluster state before joining again","If already a Secondary of the desired cluster, no action is needed","Check ClusterInitialized before attempting join"],"exampleFix":"// before\nawait clusterManager.InitializeAndJoinClusterAsync(ips, primaryUrl, user, pass);\n\n// after\nif (clusterManager.ClusterInitialized)\n    await clusterManager.LeaveClusterAsync(); // or prompt user\nawait clusterManager.InitializeAndJoinClusterAsync(ips, primaryUrl, user, pass);","handlingStrategy":"validation","validationCode":"if (clusterManager.ClusterInitialized)\n    return Conflict(\"Node is already part of a cluster; leave first.\");\nawait clusterManager.InitializeAndJoinClusterAsync(ips, primaryUrl, user, pass);","typeGuard":null,"tryCatchPattern":"catch (DnsServerException ex) when (ex.Message.Contains(\"already initialized\"))\n{ /* offer to leave current cluster and retry */ }","preventionTips":["Make join idempotent by checking ClusterInitialized first","Surface current cluster membership before offering 'join'"],"tags":["cluster","lifecycle","validation","dns-server"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}