Description
The web client instance connects (sometimes) to the old ip address of a domain name after the ip of the domain has changed by the dns. It looks like that the dns cache is not refreshed in all socket connections as it should. Only a restart of the service solves the problem.
Expected Behavior
When a ip address of a domain name changes, the ip of all socket addresses should be refreshed after the configured ttl time.
Actual Behavior
In some request the webclient connects to the old ip adress after it has changed by the dns server.
Steps to Reproduce
I can't reproduce it locally.
WebClient instance is cached in a spring service object and defined like that:
HttpClient httpClient = HttpClient.create(resourceFactory.getConnectionProvider())
.metrics(true, Function.identity())
.resolver(nameResolverSpec -> nameResolverSpec.cacheMaxTimeToLive(Duration.ofSeconds(60)))
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
.responseTimeout(Duration.ofMinutes(2));
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
network address cache is set at application startup like that:
public static void main(String[] args) {
Security.setProperty("networkaddress.cache.ttl", "60");
Security.setProperty("networkaddress.cache.negative.ttl", "0");
SpringApplication.run(Application.class, args);
}
To monitor the ip-address i have defined a scheduler job that checks every hour (by calling InetAddress.getByName("https://MyHostname")) if the ip of the hostname has changed. InetAddress.getByName returns the correct ip address when it has changed. It looks to me that the wrong ip is not cached by InetAddress.
Possible Solution
?
Your Environment
Java 17 openjdk
Spring boot dependencies 3.2.8
Reactor-netty-core 1.1.21
Netty 4.1.111.Final
Linux os