alibaba/spring-cloud-alibaba · error · IllegalStateException

Invalid redis sentinel property {}

Error message

Invalid redis sentinel property {}

What it means

Thrown by RedisDataSourceFactoryBean.getObject() when parsing a Redis Sentinel node entry fails. The FactoryBean iterates over the nodes list (each expected as 'host:port'), splits on ':', and asserts exactly two parts. If split returns null, yields != 2 parts, or Integer.parseInt(parts[1]) fails, the RuntimeException is caught and wrapped in an IllegalStateException identifying the offending node value.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/RedisDataSourceFactoryBean.java:87

	private @Nullable String masterId;

	@Override
	public RedisDataSource getObject() {
		RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder();

		if (nodes == null || nodes.isEmpty()) {
			builder.withHost(host).withPort(port).withDatabase(database);
		}
		else {
			nodes.forEach(node -> {
				try {
					String[] parts = StringUtils.split(node, ":");
					Assert.state(parts != null && parts.length == 2, "Must be defined as 'host:port'");
					builder.withRedisSentinel(parts[0], Integer.parseInt(parts[1]));
				}
				catch (RuntimeException ex) {
					throw new IllegalStateException(
							"Invalid redis sentinel property " + node, ex);
				}
			});
			builder.withSentinelMasterId(masterId);
		}

		if (timeout != null) {
			builder.withTimeout(timeout.toMillis());
		}

		if (StringUtils.hasText(password)) {
			builder.withPassword(password);
		}

		return new RedisDataSource<List<FlowRule>>(builder.build(), ruleKey, channel,
				converter);
	}

View on GitHub (pinned to 115d590110)

Solutions

  1. Format every node entry as exactly 'host:port' with a numeric port: e.g., redis-sentinel-1.local:26379,redis-sentinel-2.local:26379.
  2. Check for trailing commas, empty entries, or whitespace in the nodes list.
  3. Ensure the port is numeric and within valid range (1-65535).

Example fix

# before (broken — missing port, trailing comma)
spring:
  cloud:
    sentinel:
      datasource:
        ds1:
          redis:
            nodes:
              - redis-sentinel-1.local
              - redis-sentinel-2.local:26379,

# after (fixed)
spring:
  cloud:
    sentinel:
      datasource:
        ds1:
          redis:
            nodes:
              - redis-sentinel-1.local:26379
              - redis-sentinel-2.local:26379
Defensive patterns

Strategy: validation

Validate before calling

import java.util.List;
import org.springframework.util.StringUtils;

// Validate each node entry before FactoryBean.getObject()
List<String> nodes = props.getRedis().getNodes();
if (nodes != null) {
    for (String node : nodes) {
        String[] parts = StringUtils.split(node, ":");
        if (parts == null || parts.length != 2) {
            throw new IllegalArgumentException(
                "Invalid redis sentinel node format: '" + node + "' — must be 'host:port'");
        }
        try {
            int port = Integer.parseInt(parts[1]);
            if (port < 1 || port > 65535) {
                throw new IllegalArgumentException("Port out of range: " + port);
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(
                "Invalid port number in node: '" + node + "'");
        }
    }
}

Type guard

import java.util.regex.Pattern;

private static final Pattern HOST_PORT = Pattern.compile("^[^:]+:[0-9]{1,5}$");

boolean isValidNode(String node) {
    return node != null && HOST_PORT.matcher(node.trim()).matches();
}

Prevention

When it happens

Trigger: Configuring spring.cloud.sentinel.datasource.<name>.redis.nodes with one or more entries that do not match the 'host:port' format. Examples: missing port ('redis.local'), extra colons ('redis.local:6379:extra'), non-numeric port ('redis.local:abc'), or whitespace-only entries after splitting.

Common situations: 1) Node list entries use a different separator (e.g., 'redis.local 6379' with space instead of colon). 2) Port is omitted from one or more sentinel entries. 3) A trailing comma creates an empty entry in the list. 4) Non-numeric characters in the port field.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/2e10edc14eb0e692. Report an issue: GitHub.