I'm using JEST to connect to elasticsearch in a spring-boot application. When the application is idle (doesn't send any requests to elasticsearch) for some time, then the JestClient is throwing SocketTImeoutException. I'm creating the client using a bean:
@Bean
public JestClient client() throws Exception {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder(esURL)
.multiThreaded(true)
.connTimeout(60000)
.readTimeout(60000)
.defaultMaxTotalConnectionPerRoute(10)
.maxTotalConnection(100).build());
return factory.getObject();
}
Is there anything I'm missing here?
When the app goes idle for some time, and request arrives, then the RestHighLevelClient throws SocketTimeoutException: @Bean RestHighLevelClient client () { ClientConfiguration clientConfiguration = ClientConfiguration.builder () .connectedTo (elasticsearchHostAndPort) .build (); return RestClients.create (clientConfiguration).rest (); }
If either the accept () or read () method, blocks for more than 5 seconds, a SocketTimeoutException is thrown, designating that a timeout has occurred. It is important to note that after this exception is thrown. the socket remains valid, so you can retry the blocking call or do whatever you want with the valid socket.
Platform Notice: Server and Data Center Only. This article only applies to Atlassian products on the server and data center platforms. Certain requests to Jira using the Jira Rest java Client (JRJC) result in SocketTimeoutException when they exceed 20 seconds (20,000 milliseconds).
Signals that a timeout has occurred on a socket read or accept." To answer the question of what causes this, that would be your answer. Java was attempting to connect to a socket and it failed to connect before timing out. As for how to solve this, that depends on your use case.
An idea I would try: look into this feature - https://github.com/searchbox-io/Jest/pull/149 - meaning, configure maxConnectionIdleTime
so that the idle connections are killed before actually being used (which would result in the timeout exception you get). An example in the tests themselves: https://github.com/searchbox-io/Jest/blob/v2.0.4/jest/src/test/java/io/searchbox/client/JestClientFactoryIntegrationTest.java#L116
Regarding the value to use for it, I am not sure what is the timeout for the network socket... guessing 30 seconds. And whatever you set for the maxConnectionIdleTime
it should be less than that. Maybe try to observe from the timeouts you get what idle time protects you and which not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With