caddyserver/caddy · error
end port must not be less than start port
Error message
end port must not be less than start port
What it means
Validation guard in ParseNetworkAddressWithDefaults: when the port string is a range like '8080-80', the parsed end port is numerically less than the start port. The faulty input is the reversed port range in the listener address; both ports must be within 0-65535 and end >= start.
Solutions
- Swap the bounds so the smaller port comes first: ':8080-8090'.
- In generators, sort the pair before formatting the range.
- A single port (no hyphen) avoids range-ordering issues entirely.
Example fix
// before
{
listen :8090-8080
}
// after
{
listen :8080-8090
} Defensive patterns
Strategy: validation
Validate before calling
func orderedRange(start, end uint64) (uint64, uint64) {
if end < start { return end, start }
return start, end
} Prevention
- Sort user-supplied port pairs in tooling before formatting ranges.
- Prefer single ports unless a range is genuinely needed.
When it happens
Trigger: Any address like ':8090-8080', ':443-80', or config generation that swaps min/max when a user enters an inverted range.
Common situations: Users writing 'high-low' naturally when they mean 'any port in this span'; automation that concatenates two user-supplied numbers without ordering them.
Related errors
- invalid end port
- port range exceeds ports
- invalid start port
- acme challenge is not supported
- automation policy : cannot apply more than one automation…
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/fdf8c23c814eb374.
Report an issue: GitHub.
Appendix: source
Thrown at listeners.go:362
var start, end uint64
if port == "" {
start = uint64(defaultPort)
end = uint64(defaultPort)
} else {
before, after, found := strings.Cut(port, "-")
if !found {
after = before
}
start, err = strconv.ParseUint(before, 10, 16)
if err != nil {
return NetworkAddress{}, fmt.Errorf("invalid start port: %v", err)
}
end, err = strconv.ParseUint(after, 10, 16)
if err != nil {
return NetworkAddress{}, fmt.Errorf("invalid end port: %v", err)
}
if end < start {
return NetworkAddress{}, fmt.Errorf("end port must not be less than start port")
}
if (end - start) > maxPortSpan {
return NetworkAddress{}, fmt.Errorf("port range exceeds %d ports", maxPortSpan)
}
}
return NetworkAddress{
Network: network,
Host: host,
StartPort: uint(start),
EndPort: uint(end),
}, nil
}
// SplitNetworkAddress splits a into its network, host, and port components.
// Note that port may be a port range (:X-Y), or omitted for unix sockets.
func SplitNetworkAddress(a string) (network, host, port string, err error) {
beforeSlash, afterSlash, slashFound := strings.Cut(a, "/")
if slashFound {View on GitHub (pinned to 50e54ee279)