dgraph-io/dgraph · error

Hostname should be less than or equal to 255 characters

Error message

Hostname should be less than or equal to 255 characters

What it means

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.

Source

Thrown at x/x.go:860

	}
	return start, end
}

// ValidateAddress checks whether given address can be used with grpc dial function
func ValidateAddress(addr string) error {
	host, port, err := net.SplitHostPort(addr)
	if err != nil {
		return err
	}
	if p, err := strconv.Atoi(port); err != nil || p <= 0 || p >= 65536 {
		return errors.Errorf("Invalid port: %v", p)
	}
	if ip := net.ParseIP(host); ip != nil {
		return nil
	}
	// try to parse as hostname as per hostname RFC
	if len(strings.Replace(host, ".", "", -1)) > 255 {
		return errors.Errorf("Hostname should be less than or equal to 255 characters")
	}
	if !regExpHostName.MatchString(host) {
		return errors.Errorf("Invalid hostname: %v", host)
	}
	return nil
}

// RemoveDuplicates sorts the slice of strings and removes duplicates. changes the input slice.
// This function should be called like: someSlice = RemoveDuplicates(someSlice)
func RemoveDuplicates(s []string) (out []string) {
	sort.Strings(s)
	out = s[:0]
	for i := range s {
		if i > 0 && s[i] == s[i-1] {
			continue
		}
		out = append(out, s[i])
	}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Shorten the hostname to 255 characters or fewer (excluding dots)
  2. Verify the config value is a single hostname, not a URL or list
  3. If the value is an IP, provide it in valid IP form so parsing short-circuits

Example fix

// before
host := "very-long-sub1.sub2....example.com" // > 255 chars
err := ValidateHost(host)
// after
host := "svc.example.com"
err := ValidateHost(host)
Defensive patterns

Strategy: validation

Validate before calling

func validHostnameLength(host string) bool {
    if net.ParseIP(host) != nil { return true }
    return len(strings.ReplaceAll(host, ".", "")) <= 255
}

Type guard

func isShortHostname(host string) bool { return len(strings.ReplaceAll(host, ".", "")) <= 255 }

Prevention

When it happens

Trigger: Passing a host string longer than 255 characters (excluding dots) to the hostname validation function — typically via a server/endpoint configuration value.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/ef17a8ec9239cbe9. Report an issue: GitHub.