I have noticed that after upgrading my service to Java api client it is giving random connection reset by peer error, where the 1 st request always failed , later it worked and after 10 minutes this happens again. My service started and sent a query to ES and everything worked well. After 10 minutes I sent insert request and it failed on connection reset by peer.
I have tried updating the connection timeout parameters as mentioned in the configuration here, but it didn't work.
Any thoughts?
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\n\t... 38 common frames omitted\nCaused by: java.io.IOException: Connection reset by peer\n\tat org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:885)\n\tat org.elasticsearch.client.RestClient.performRequest(RestClient.java:283)\n\tat org.elasticsearch.client.RestClient.performRequest(RestClient.java:270)\n\tat co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:146)\n\tat co.elastic.clients.elasticsearch.ElasticsearchClient.index(ElasticsearchClient.java:946)\n\tat com.xxx.xxx.search.manager.data.ElasticSearchRepository.indexEntity(ElasticSearchRepository.java:51)\n\t... 52 common frames omitted\nCaused by: java.io.IOException: Connection reset by peer\n\tat sun.nio.ch.FileDispatcherImpl.read0(Native Method)\n\tat sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)\n\tat sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)\n\tat sun.nio.ch.IOUtil.read(IOUtil.java:197)\n\tat sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)\n\tat org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(SSLIOSession.java:478)\n\tat org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:540)\n\tat org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:120)\n\tat org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)\n\tat org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)\n\tat org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)\n\tat org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)\n\tat org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)\n\tat org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)\n\t... 1 common frames
Configuration:
@Configuration
@ConfigurationProperties(prefix = "es")
@ComponentScan(basePackages = {"com.xxx.xxx"})
public class ElasticSearchConfiguration {
@Value("#{'${es.hosts}'.split(',')}")
private List<String> hosts;
@Value("${es.port}")
private Integer port;
@Value("${es.scheme}")
private String scheme;
@Value("${es.username}")
private String username;
@Value("${es.password}")
private String password;
@Bean
public ElasticsearchClient client() {
return new ElasticsearchClient(transport());
}
private ElasticsearchTransport transport() {
return new RestClientTransport(restClient(),new JacksonJsonpMapper());
}
@Bean
public RestClient restClient() {
HttpHost[] extractHosts = extractHosts(hosts, scheme);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
return RestClient.builder(extractHosts)
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
.setConnectTimeout(10000)
.setSocketTimeout(60000)).build();
}
private HttpHost[] extractHosts(List<String> hosts, String scheme) {
return hosts.stream().map(extractHost -> new HttpHost(extractHost, port, scheme)).toArray(HttpHost[]::new);
}
}