alibaba/Sentinel · error · IllegalStateException

No port present.

Error message

No port present.

What it means

Thrown by RedisHostAndPort.getPort() when the value holds no port. RedisHostAndPort parses strings like "host:6379"; if the input had no ":port" part, hasPort() is false and any getPort() call throws this IllegalStateException. It typically fires inside RedisConnectionConfig while assembling standalone/sentinel/cluster connections.

Source

Thrown at sentinel-extension/sentinel-datasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/config/RedisHostAndPort.java:75

     * @return {@literal true} if has a port.
     */
    public boolean hasPort() {
        return port != NO_PORT;
    }

    /**
     * @return the host text.
     */
    public String getHost() {
        return host;
    }

    /**
     * @return the port.
     */
    public int getPort() {
        if (!hasPort()) {
            throw new IllegalStateException("No port present.");
        }
        return port;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof RedisHostAndPort)) {
            return false;
        }
        RedisHostAndPort that = (RedisHostAndPort)o;
        return port == that.port && (host != null ? host.equals(that.host) : that.host == null);
    }

    @Override
    public int hashCode() {

View on GitHub (pinned to a3f40ba8e9)

Solutions

  1. Include the port in the host/node strings: "redis.prod:6379", sentinel entries like "sentinel-1:26379".
  2. If the property may lack a port, normalize it before use: host.contains(":") ? host : host + ":6379" (choose the correct default: 6379 standalone, 26379 sentinel, per your topology).
  3. Call hasPort() before getPort() when you handle parsed RedisHostAndPort values yourself.

Example fix

// before
RedisHostAndPort hp = RedisHostAndPort.from("redis.prod");
int port = hp.getPort(); // throws "No port present."

// after
RedisHostAndPort hp = RedisHostAndPort.from("redis.prod:6379");
int port = hp.getPort();
Defensive patterns

Strategy: validation

Validate before calling

String normalized = host.contains(":") ? host : host + ":6379"; // 26379 for sentinels
RedisHostAndPort hp = RedisHostAndPort.from(normalized);
int port = hp.getPort(); // safe

// or check first:
if (!hp.hasPort()) { throw new IllegalStateException("redis host missing port: " + host); }

Try / catch

try {
    int port = hp.getPort();
} catch (IllegalStateException e) {
    throw new IllegalStateException("Redis address '" + rawHost + "' must include a port", e);
}

Prevention

When it happens

Trigger: Building a config from a host string without a port, e.g. RedisConnectionConfig.Builder.withHost("redis.prod") combined with logic that later calls getPort() on a RedisHostAndPort parsed from "redis.prod"; or a sentinel/cluster node list entry missing ":port" ("redis-node1" instead of "redis-node1:26379").

Common situations: Operators assume a default port and omit it in config; host property contains only the hostname while the code path requires an explicit RedisHostAndPort with port; environment difference where staging configs include ports but production does not.

Related errors


AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14). Data as JSON: /api/errors/bc9732b5c7f67d0a. Report an issue: GitHub.