{"record":{"id":"ef17a8ec9239cbe9","repo":"dgraph-io/dgraph","slug":"hostname-should-be-less-than-or-equal-to-255-chara","errorCode":null,"errorMessage":"Hostname should be less than or equal to 255 characters","messagePattern":"Hostname should be less than or equal to 255 characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/x.go","lineNumber":860,"sourceCode":"\t}\n\treturn start, end\n}\n\n// ValidateAddress checks whether given address can be used with grpc dial function\nfunc ValidateAddress(addr string) error {\n\thost, port, err := net.SplitHostPort(addr)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif p, err := strconv.Atoi(port); err != nil || p <= 0 || p >= 65536 {\n\t\treturn errors.Errorf(\"Invalid port: %v\", p)\n\t}\n\tif ip := net.ParseIP(host); ip != nil {\n\t\treturn nil\n\t}\n\t// try to parse as hostname as per hostname RFC\n\tif len(strings.Replace(host, \".\", \"\", -1)) > 255 {\n\t\treturn errors.Errorf(\"Hostname should be less than or equal to 255 characters\")\n\t}\n\tif !regExpHostName.MatchString(host) {\n\t\treturn errors.Errorf(\"Invalid hostname: %v\", host)\n\t}\n\treturn nil\n}\n\n// RemoveDuplicates sorts the slice of strings and removes duplicates. changes the input slice.\n// This function should be called like: someSlice = RemoveDuplicates(someSlice)\nfunc RemoveDuplicates(s []string) (out []string) {\n\tsort.Strings(s)\n\tout = s[:0]\n\tfor i := range s {\n\t\tif i > 0 && s[i] == s[i-1] {\n\t\t\tcontinue\n\t\t}\n\t\tout = append(out, s[i])\n\t}","sourceCodeStart":842,"sourceCodeEnd":878,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/x.go#L842-L878","documentation":"Hostname validation per RFC 952/1123: a hostname whose characters (dots removed) total more than 255 is rejected. This check runs in x.go's ValidateHost-style function after IP parsing fails, enforcing the DNS length limit before the hostname is used.","triggerScenarios":"Passing a host string longer than 255 characters (excluding dots) to the hostname validation function — typically via a server/endpoint configuration value.","commonSituations":"Pasting an oversized concatenated string (e.g. multiple hosts or a full URL) into a hostname field, generated hostnames from templating that balloon in length, or misconfigured multi-label internal names.","solutions":["Shorten the hostname to 255 characters or fewer (excluding dots)","Verify the config value is a single hostname, not a URL or list","If the value is an IP, provide it in valid IP form so parsing short-circuits"],"exampleFix":"// before\nhost := \"very-long-sub1.sub2....example.com\" // > 255 chars\nerr := ValidateHost(host)\n// after\nhost := \"svc.example.com\"\nerr := ValidateHost(host)","handlingStrategy":"validation","validationCode":"func validHostnameLength(host string) bool {\n    if net.ParseIP(host) != nil { return true }\n    return len(strings.ReplaceAll(host, \".\", \"\")) <= 255\n}","typeGuard":"func isShortHostname(host string) bool { return len(strings.ReplaceAll(host, \".\", \"\")) <= 255 }","tryCatchPattern":null,"preventionTips":["Keep configured hostnames within RFC 255-character limits","Store hostnames, not full URLs or host lists, in hostname fields","Trim/normalize config values at load time"],"tags":["hostname","validation","dns"],"backgroundTag":"invalid-hostname","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}