XTLS/Xray-core · info

invalid port range:

Error message

invalid port range: 

What it means

Returned by parseStringPort in infra/conf/common.go when strings.SplitN(s, "-", 2) yields an empty slice. Because strings.SplitN always returns at least one element, this branch is effectively defensive/unreachable; in practice the companion errors from net.PortFromString (invalid number, out-of-range port) are what you hit for bad port strings. The condition exists to guard future refactors of the splitting logic.

Source

Thrown at infra/conf/common.go:138

}

func parseIntPort(data []byte) (net.Port, error) {
	var intPort uint32
	err := json.Unmarshal(data, &intPort)
	if err != nil {
		return net.Port(0), err
	}
	return net.PortFromInt(intPort)
}

func parseStringPort(s string) (net.Port, net.Port, error) {
	if strings.HasPrefix(s, "env:") {
		s = platform.NewEnvFlag(s[4:]).GetValue(func() string { return "" })
	}

	pair := strings.SplitN(s, "-", 2)
	if len(pair) == 0 {
		return net.Port(0), net.Port(0), errors.New("invalid port range: ", s)
	}
	if len(pair) == 1 {
		port, err := net.PortFromString(pair[0])
		return port, port, err
	}

	fromPort, err := net.PortFromString(pair[0])
	if err != nil {
		return net.Port(0), net.Port(0), err
	}
	toPort, err := net.PortFromString(pair[1])
	if err != nil {
		return net.Port(0), net.Port(0), err
	}
	return fromPort, toPort, nil
}

func parseJSONStringPort(data []byte) (net.Port, net.Port, error) {

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. If you see a port parse error, check the actual port values: they must be integers 1-65535
  2. For range strings use 'from-to' with from <= to, e.g. "1000-2000"
  3. For env form "env:PORT_VAR", verify the variable resolves to a valid port or range
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Cannot be triggered through normal input since SplitN never returns a zero-length slice for any string, including the empty string. The reachable failures for 'env:'-resolved or 'a-b' port strings surface as PortFromString errors instead.

Common situations: Developers grepping for this message after seeing port errors usually actually hit net.PortFromString errors (e.g. port 70000 or 'abc'); this specific message appearing in logs would indicate a modified/forked split helper.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/8a06c4020ce87d92. Report an issue: GitHub.