ReadTimeoutException on outbound connections
See original GitHub issueOur set up uses Springboot + Webflux to implement micro services. On receipt of request we transform the request and make outbound requests using WebClient. Our connections are pooled. Below is the typical configuration
Connection Pool creation
private ConnectionProvider connectionProvider() {
return ConnectionProvider
.builder("default)
.maxConnections(500)
.maxIdleTime(Duration.ofSeconds(30))
.maxLifeTime(Duration.ofSeconds(60))
.evictInBackground(Duration.ofSeconds(120))
.metrics(true)
.disposeInactivePoolsInBackground(Duration.ofSeconds(180), Duration.ofSeconds(175))
.build();
}
HttpClient creation
public HttpClient httpClient() {
var customLoggingHandler = new HttpLoggingHandler(HttpClient.class);
var httpClient = HttpClient
.create(connectionProvider())
.responseTimeout(Duration.ofMillis(28500))
.runOn(LoopResources.create("reactor-client-nio"))
.doOnRequest((request, connection) -> connection.addHandlerFirst(customLoggingHandler))
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 28500);
SslContext sslContext = sslContextFactory.newSslContext();
if (sslContext != null) {
httpClient = httpClient.secure(sslProvider -> sslProvider.sslContext(sslContext));
}
return httpClient;
}
ReactorHttpClientConfiguration
@Bean
public ReactorClientHttpConnector standardWebClientConnector(StandardHttpClientConfigProperties config, SslContextFactory sslContextFactory) {
HttpClient httpClient = new HttpClientFactory(config.getHttpClient(), sslContextFactory).httpClient();
return new ReactorClientHttpConnector(httpClient);
}
WebClient creation
@Bean
@Qualifier("externalWebClient")
public WebClient webClient(WebClient.Builder webClientBuilder,
ReactorClientHttpConnector standardWebClientConnector, ExchangeStrategies exchangeStrategies) {
return webClientBuilder
.exchangeStrategies(exchangeStrategies)
.clientConnector(standardWebClientConnector)
.build();
}
In environments where there is less traffic we see ReadTimeoutException if the request takes more than 28500ms but in environments where there is high traffic we see ReadTimeoutException within few seconds of request being made. Below are the logs lines
{"log":"2021-07-03 15:30:21:314 [nt-epoll-3] ERROR .controller.AbstractController a7d8797f-63da-4ab3-aae0-f4d3034afac3 - Unknown exception\n","stream":"stdout","time":"2021-07-03T05:30:21.315151481Z"}
{"log":"org.springframework.web.reactive.function.client.WebClientRequestException: nested exception is io.netty.handler.timeout.ReadTimeoutException\n"
{"log":"2021-07-03 15:30:20:228 [nt-epoll-3] DEBUG efaultPooledConnectionProvider a7d8797f-63da-4ab3-aae0-f4d3034afac3 - [id:77ed51a6-3, L:/10.70.12.98:55550 - R:www.acme.com.au/13.226.106.76:443] onStateChange(GET{uri=/uri/test, connection=PooledConnection{channel=[id: 0x77ed51a6, L:/10.70.12.98:55550 - R:www.acme.com.au/13.226.106.76:443]}}, [request_sent])\n","stream":"stdout","time":"2021-07-03T05:30:20.228483504Z"}
{"log":"2021-07-03 15:30:20:227 [nt-epoll-3] DEBUG efaultPooledConnectionProvider a7d8797f-63da-4ab3-aae0-f4d3034afac3 - [id:77ed51a6-3, L:/10.70.12.98:55550 - R:www.acme.com.au/13.226.106.76:443] onStateChange(GET{uri=/uri/test, connection=PooledConnection{channel=[id: 0x77ed51a6, L:/10.70.12.98:55550 - R:www.acme.com.au/13.226.106.76:443]}}, [request_prepared])\n","stream":"stdout","time":"2021-07-03T05:30:20.228403471Z"}
I have been trying to identify patterns as to when this can happen but no luck so far. We are using reactory-netty
version 1.0.7
and springboot
version 2.5.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
java - Reusing routes for inbound/outbound communication
I solved this by having the external server poll for data that would normally be sent through the second route. Every message is...
Read more >reactor/reactor - Gitter
The connection observed an error 2019-03-26T18:45:46.05-0400 [APP/PROC/WEB/0] OUT io.netty.handler.timeout.ReadTimeoutException: null ...
Read more >ReadTimeoutException (Netty API Reference (4.1.85.Final))
A TimeoutException raised by ReadTimeoutHandler when no data was read within a certain period of time. See Also: Serialized Form ...
Read more >Set a Timeout in Spring 5 Webflux WebClient - Baeldung
The connection timeout is a period within which a connection between a ... The underlying Netty library delivers ReadTimeoutException and ...
Read more >Using the SAP Ariba Adapter with Oracle Integration
Read Time Out Exception Error Due to Frequent Data Transfer Events · Exception occured inside ITKEndpoint : invoke : java.net.SocketTimeoutException: · Read timed ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@itsnagaraj That’s very interesting. Thanks a lot for the logs.
I think that the issue is that we never observe
Removed handler ...
but ratherHandler [reactor.left.responseTimeoutHandler] already exists in the pipeline ...
I need to check what’s going on.
After aligning the versions of
com.newrelic.telemetry:micrometer-registry-new-relic
andcom.newrelic.agent.java:newrelic-api
with the version ofspringboot
currently used we are no longer seeing the issue in our higher environments.