apache/flink · error · IllegalConfigurationException

Invalid port configuration. Port must be between 0and 65535,

Error message

Invalid port configuration. Port must be between 0and 65535, but range end was {}.

What it means

NetUtils.getPortRangeFromString validates the end bound of a 'start-end' range entry; an end outside 0..65535 throws IllegalConfigurationException with 'range end was <n>'. It fires only after the start bound already passed validation. Pure config validation, thrown before any socket work.

Source

Thrown at flink-core/src/main/java/org/apache/flink/util/NetUtils.java:444

                            "Invalid port configuration. Port must be between 0"
                                    + "and 65535, but was "
                                    + port
                                    + ".");
                }
                rangeIterator = Collections.singleton(Integer.valueOf(range)).iterator();
            } else {
                // evaluate range
                final int start = Integer.parseInt(range.substring(0, dashIdx));
                if (!isValidHostPort(start)) {
                    throw new IllegalConfigurationException(
                            "Invalid port configuration. Port must be between 0"
                                    + "and 65535, but range start was "
                                    + start
                                    + ".");
                }
                final int end = Integer.parseInt(range.substring(dashIdx + 1));
                if (!isValidHostPort(end)) {
                    throw new IllegalConfigurationException(
                            "Invalid port configuration. Port must be between 0"
                                    + "and 65535, but range end was "
                                    + end
                                    + ".");
                }
                if (start >= end) {
                    throw new IllegalConfigurationException(
                            "Invalid port configuration."
                                    + " Port range end must be bigger than port range start."
                                    + " If you wish to use single port please provide the value directly, not as a range."
                                    + " Given range: "
                                    + range);
                }
                rangeIterator =
                        new Iterator<Integer>() {
                            int i = start;

                            @Override

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Fix the end value to a valid port within 0..65535 and greater than the start.
  2. Check the echoed value and confirm the template/variable feeding it.
  3. Validate generated range strings in tests before shipping config.

Example fix

# before
rest.bind-port: 8081-65536

# after
rest.bind-port: 8081-8181
Defensive patterns

Strategy: validation

Validate before calling

static void validatePortRangeFull(String def) {
    for (String part : def.split(",")) {
        String[] bounds = part.trim().split("-", 2);
        int start = Integer.parseInt(bounds[0]);
        int end = bounds.length > 1 ? Integer.parseInt(bounds[1]) : start;
        Preconditions.checkArgument(end >= 0 && end <= 65535, "bad range end: %s", part);
    }
}

Prevention

When it happens

Trigger: Range strings like '8081-99999' or '1000--1' whose second parsed integer fails isValidHostPort; building ranges via string concatenation that produces an invalid upper bound.

Common situations: Typos in the upper bound; copy-paste of ranges between configs; template variables for the upper bound resolving to invalid values.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/3cc808cbc0e21579. Report an issue: GitHub.