Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JestClient is throwing SocketTimeoutException after being idle for sometime

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?

like image 681
pkgajulapalli Avatar asked Jan 13 '18 04:01

pkgajulapalli


People also ask

When does the resthighlevelclient throw sockettimeoutexception?

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 (); }

What is sockettimeoutexception in Java?

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.

What is sockettimeoutexception in Atlassian JIRA?

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).

What causes a socket timeout in Java?

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.


1 Answers

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.

like image 63
Andrei Stefan Avatar answered Sep 23 '22 00:09

Andrei Stefan