apache/shenyu · error · IllegalArgumentException

Invalid format in Redis node URL: " + url

Error message

Invalid format in Redis node URL: " + url

What it means

RedisConnectionFactory.parseRedisNode validates host:port node strings when building Redis cluster/sentinel nodes. If the string contains a colon but the colon is the first or last character (e.g. ':6379' or 'myhost:'), the host/port split is ambiguous and it throws IllegalArgumentException. This guards against malformed node URLs before a RedisNode is constructed.

Solutions

  1. Fix the node URL so it is in host:port form, e.g. '127.0.0.1:6379'
  2. Trim whitespace and remove empty entries from the configured node list
  3. Log the full configured nodes string and correct the offending entry
  4. Add pre-validation of node strings before calling RedisConnectionFactory

Example fix

// before
shenyu.redis.nodes=192.168.0.1:6379,:6379,192.168.0.2:
// after
shenyu.redis.nodes=192.168.0.1:6379,192.168.0.2:6379
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidNode(String url) {
    if (url == null) return false;
    String t = url.trim();
    int i = t.lastIndexOf(':');
    return i > 0 && i < t.length() - 1;
}

Try / catch

try {
    RedisNode node = RedisConnectionFactory.parseRedisNode(url);
} catch (IllegalArgumentException e) {
    log.error("bad redis node url: {}", url, e);
    throw new ConfigurationException("fix redis.nodes entry", e);
}

Prevention

When it happens

Trigger: Passing a node string with a leading colon (no host), a trailing colon (no port), e.g. 'redis.nodes=:,host:, :6379' in cluster config parsed via redisNode/createRedisNode.

Common situations: Copy-paste of cluster node lists with stray separators, YAML/properties lists accidentally containing empty entries (trailing or leading commas yielding empty strings with colons), templated config where a host variable did not substitute.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/da629bc0d26e30bb. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-infra/shenyu-infra-redis/src/main/java/org/apache/shenyu/infra/redis/RedisConnectionFactory.java:187

                    throw new IllegalArgumentException("Invalid port in Redis node URL: " + url, e);
                }
            }
        } else {
            // IPv4 or hostname format: localhost:6379 or 192.168.1.1:6379
            int lastColonIndex = trimmedUrl.lastIndexOf(":");
            if (lastColonIndex > 0 && lastColonIndex < trimmedUrl.length() - 1) {
                String portStr = trimmedUrl.substring(lastColonIndex + 1);
                if (portStr.isEmpty()) {
                    throw new IllegalArgumentException("Port cannot be empty in Redis node URL: " + url);
                }
                try {
                    port = Integer.parseInt(portStr);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Invalid port in Redis node URL: " + url, e);
                }
                host = trimmedUrl.substring(0, lastColonIndex);
            } else if (lastColonIndex == 0 || lastColonIndex == trimmedUrl.length() - 1) {
                throw new IllegalArgumentException("Invalid format in Redis node URL: " + url);
            }
        }
        
        if (host.trim().isEmpty()) {
            throw new IllegalArgumentException("Host is empty in Redis node URL: " + url);
        }
        if (port < 1 || port > 65535) {
            throw new IllegalArgumentException("Port out of range (1-65535) in Redis node URL: " + url);
        }
        
        return new RedisNode(host.trim(), port);
    }
}

View on GitHub (pinned to 567142e072)