{"record":{"id":"e3452452de40e6fb","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-generate-unique-label-for-the-given-doma","errorCode":null,"errorMessage":"Failed to generate unique label for the given domain name '{domain}'. Please try again.","messagePattern":"Failed to generate unique label for the given domain name '(.+?)'\\. Please try again\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"warning","filePath":"DnsServerCore/Dns/Zones/CatalogZone.cs","lineNumber":386,"sourceCode":"        private string GetDomainWithLabel(string domain)\n        {\n            Span<byte> buffer = stackalloc byte[8];\n            int i = 0;\n\n            do\n            {\n                RandomNumberGenerator.Fill(buffer);\n                string label = Base32.ToBase32HexString(buffer, true).ToLowerInvariant();\n                string domainWithLabel = label + \".\" + domain;\n\n                if (_dnsServer.AuthZoneManager.NameExists(_name, domainWithLabel))\n                    continue;\n\n                return domainWithLabel;\n            }\n            while (++i < 10);\n\n            throw new DnsServerException(\"Failed to generate unique label for the given domain name '\" + domain + \"'. Please try again.\");\n        }\n\n        #endregion\n\n        #region public\n\n        public override string GetZoneTypeName()\n        {\n            return \"Catalog\";\n        }\n\n        public override void SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records)\n        {\n            switch (type)\n            {\n                case DnsResourceRecordType.SOA:\n                    if ((records.Count != 1) || !records[0].Name.Equals(_name, StringComparison.OrdinalIgnoreCase))\n                        throw new InvalidOperationException(\"Invalid SOA record.\");","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Zones/CatalogZone.cs#L368-L404","documentation":"CatalogZone.GetDomainWithLabel generates a random 8-byte label (Base32-hex encoded) and prepends it to a domain name to create a unique name under the catalog zone. It retries up to 10 times, checking NameExists each iteration. If all 10 attempts produce names that already exist, it throws DnsServerException. With 8 random bytes (2^64 possibilities) this should be cryptographically impossible under normal conditions — hitting it indicates either a bug in the RNG, extreme collision, or the NameExists check is malfunctioning.","triggerScenarios":"Internally called when adding a new member zone to the catalog (generating a unique version label per RFC 9432 section 3.1). The exception fires if 10 consecutive random 8-byte labels all collide with existing names.","commonSituations":"Extremely unlikely under normal operation due to 64-bit randomness. Could occur if RandomNumberGenerator.Fill is broken/degraded, if the zone is in a corrupted state where NameExists always returns true, or in pathological test environments with mocked RNG. The error message says 'Please try again' implying a transient condition.","solutions":["Retry the operation — the error message explicitly suggests this, and a new random draw will almost certainly succeed.","If it persists, check the catalog zone for corruption (orphaned entries that make NameExists malfunction).","Restart the DNS server process to reset the RNG state if a systemic RNG issue is suspected.","Investigate whether the catalog zone has an abnormally large number of entries that could increase collision probability (should not with 64-bit labels)."],"exampleFix":"// before (internal call fails 10 times)\ncatalogZone.AddMemberZone(domain);\n// throws: Failed to generate unique label\n\n// after (retry pattern)\nfor (int attempt = 0; attempt < 3; attempt++)\n{\n    try { catalogZone.AddMemberZone(domain); break; }\n    catch (DnsServerException) when (attempt < 2) { continue; }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"int maxRetries = 3;\nfor (int i = 0; i < maxRetries; i++)\n{\n    try { catalogZone.AddMemberZone(domain); break; }\n    catch (DnsServerException ex) when (ex.Message.Contains(\"Failed to generate unique label\") && i < maxRetries - 1)\n        { continue; }\n}","preventionTips":["Wrap catalog member-add operations in a retry loop (the error message explicitly says 'try again').","Monitor for persistent failures which indicate RNG or zone-state corruption.","Keep catalog zone member count reasonable to avoid edge-case collision scenarios."],"tags":["dns","catalog-zone","rfc-9432","random","collision","retry"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}