Skip to content

NumberFormatException when configuring spring.redis.sentinel.nodes with an IPv6 address #32762

@vcfee

Description

@vcfee

This yaml :

spring:
  redis:
    sentinel:
      master: mymaster
      nodes: "[2409:aaa:5a00::fdfb:1:aaa]:26379,[2409:80aaa50:5a00::fdfb:1:bbb]:26379,[2409:aaa:5a00::fdfb:1:ccc]:26379"

but fails with:

Caused by: java.lang.NumberFormatException: For input string: "aaa:5a00::fdfb:1:aaa]:26379"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_331]
	at java.lang.Integer.parseInt(Integer.java:580) ~[?:1.8.0_331]
	at java.lang.Integer.parseInt(Integer.java:615) ~[?:1.8.0_331]
	at org.springframework.boot.autoconfigure.data.redis.RedisConnectionConfiguration.createSentinels(RedisConnectionConfiguration.java:150) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.data.redis.RedisConnectionConfiguration.getSentinelConfig(RedisConnectionConfiguration.java:97) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]

This issue is somewhat similar to #28133 and spring-projects/spring-data-redis#2418 (comment)

spring boot autoconfigure ipv6 address all split by ":"

private List<RedisNode> createSentinels(RedisProperties.Sentinel sentinel) {
		List<RedisNode> nodes = new ArrayList<>();
		for (String node : sentinel.getNodes()) {
			try {
				String[] parts = StringUtils.split(node, ":");
				Assert.state(parts.length == 2, "Must be defined as 'host:port'");
				nodes.add(new RedisNode(parts[0], Integer.parseInt(parts[1])));
			}
			catch (RuntimeException ex) {
				throw new IllegalStateException("Invalid redis sentinel property '" + node + "'", ex);
			}
		}
		return nodes;
	}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions