-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StackOverflowError while RestClient.retryIfPossible #25306
Comments
@javanna what do you think about this one? |
I can't reproduce the issue. The RestClient should try to execute the request multiple times for 30s and then it should gives up and calls the onFailure() method of the listener. Could you please share with us the Java code of how the RestClient is used? Also, could you provide more logs (in order to see if there's an exception somewhere)? Finally, can you try to reproduce using a more recent version? There's a small fix (#23307) I think of that should have been part of 5.2.2 but apparently it's not. |
my shorthanded code is below. import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpHost;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;
import org.elasticsearch.client.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList;
public class Test222 {
private static final Logger logger = LoggerFactory.getLogger(Test222.class);
private static final int CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
private static final int MAX_RETRY_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
private static final int THREAD_SIZE = 200;
private static final ConcurrentHashMap<String, RestClient> map = new ConcurrentHashMap<>();
public static void main(String[] args) throws InterruptedException {
RestClient client1 = buildRestClient(
ImmutableList.of("cluster1-host1", "cluster1-host2", "cluster1-host3"));
RestClient client2 = buildRestClient(
ImmutableList.of("cluster2-host1", "cluster2-host2", "cluster2-host3"));
ErrorLoggingListener errorLogger1 = new ErrorLoggingListener("cluster1", "index1");
ErrorLoggingListener errorLogger2 = new ErrorLoggingListener("cluster2", "index2");
ExecutorService executorService = Executors.newFixedThreadPool(1000);
for (int i = 0; i < 200; i++) {
executorService.submit(() -> {
client1.performRequestAsync("methods", "endpoint", errorLogger1);
client2.performRequestAsync("methods", "endpoint", errorLogger2);
});
}
for (int i = 0; i < 200; i++) {
executorService.submit(() -> {
client1.performRequestAsync("methods", "endpoint", errorLogger1);
});
}
}
private static class ErrorLoggingListener implements ResponseListener {
private final String clusterName;
private final String indexName;
ErrorLoggingListener(String clusterName, String indexName) {
this.clusterName = clusterName;
this.indexName = indexName;
}
@Override
public void onSuccess(Response response) {
}
@Override
public void onFailure(Exception exception) {
logger.error("{} {} es ops.", clusterName, indexName, exception);
}
}
private static RestClient buildRestClient(List<String> servers) {
HttpHost[] hosts = servers.stream().map(HttpHost::create).toArray(HttpHost[]::new);
return RestClient.builder(hosts)
.setRequestConfigCallback(builder -> builder.setConnectTimeout(CONNECT_TIMEOUT)
.setSocketTimeout(SOCKET_TIMEOUT))
.setHttpClientConfigCallback(builder -> builder.setDefaultIOReactorConfig(
IOReactorConfig.custom().setIoThreadCount(THREAD_SIZE).build()))
.setMaxRetryTimeoutMillis(MAX_RETRY_TIMEOUT).build();
}
} |
below is my stack trace,It seldom happen. but when it is happeing,many errors like this is thrown : ERROR I/O dispatcher 46 (DefaultUncaughtExceptionHandlerRegistry.java:23) - uncaught exception occurred on thread [Thread[I/O dispatcher 46,5,main]]
java.lang.StackOverflowError: null
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1535)
at org.elasticsearch.client.RestClient.onFailure(RestClient.java:437)
at org.elasticsearch.client.RestClient.access$400(RestClient.java:84)
at org.elasticsearch.client.RestClient$1.failed(RestClient.java:331)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.connectionRequestFailed(AbstractClientExchangeHandler.java:335)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.access$100(AbstractClientExchangeHandler.java:62)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler$1.failed(AbstractClientExchangeHandler.java:378)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.failed(PoolingNHttpClientConnectionManager.java:504)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.nio.pool.AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:454)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:286)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:266)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:363)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:125)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:68)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:300)
at org.elasticsearch.client.RestClient.access$600(RestClient.java:84)
at org.elasticsearch.client.RestClient$1.retryIfPossible(RestClient.java:350)
at org.elasticsearch.client.RestClient$1.failed(RestClient.java:332)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.connectionRequestFailed(AbstractClientExchangeHandler.java:335)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.access$100(AbstractClientExchangeHandler.java:62)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler$1.failed(AbstractClientExchangeHandler.java:378)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.failed(PoolingNHttpClientConnectionManager.java:504)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.nio.pool.AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:454)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:286)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:266)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:363)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:125)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:68)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:300)
at org.elasticsearch.client.RestClient.access$600(RestClient.java:84)
at org.elasticsearch.client.RestClient$1.retryIfPossible(RestClient.java:350)
at org.elasticsearch.client.RestClient$1.failed(RestClient.java:332)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.connectionRequestFailed(AbstractClientExchangeHandler.java:335)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.access$100(AbstractClientExchangeHandler.java:62)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler$1.failed(AbstractClientExchangeHandler.java:378)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.failed(PoolingNHttpClientConnectionManager.java:504)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.nio.pool.AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:454)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:286)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:266)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:363)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:125)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:68)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:300)
at org.elasticsearch.client.RestClient.access$600(RestClient.java:84)
at org.elasticsearch.client.RestClient$1.retryIfPossible(RestClient.java:350)
at org.elasticsearch.client.RestClient$1.failed(RestClient.java:332)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.connectionRequestFailed(AbstractClientExchangeHandler.java:335)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.access$100(AbstractClientExchangeHandler.java:62)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler$1.failed(AbstractClientExchangeHandler.java:378)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.failed(PoolingNHttpClientConnectionManager.java:504)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.nio.pool.AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:454)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:286)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:266)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:363)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:125)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:68)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:300)
at org.elasticsearch.client.RestClient.access$600(RestClient.java:84)
at org.elasticsearch.client.RestClient$1.retryIfPossible(RestClient.java:350)
at org.elasticsearch.client.RestClient$1.failed(RestClient.java:332)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.connectionRequestFailed(AbstractClientExchangeHandler.java:335)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.access$100(AbstractClientExchangeHandler.java:62)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler$1.failed(AbstractClientExchangeHandler.java:378)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.failed(PoolingNHttpClientConnectionManager.java:504)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
at org.apache.http.nio.pool.AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:454)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:286)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:266)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:363)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:125)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:68)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:300)
at org.elasticsearch.client.RestClient.access$600(RestClient.java:84)
at org.elasticsearch.client.RestClient$1.retryIfPossible(RestClient.java:350)
at org.elasticsearch.client.RestClient$1.failed(RestClient.java:332)
at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134) |
Thanks for the information. Sadly I still can't reproduce but I'd be happy if you can test against with a more recent version. |
No further feedback. If you are able to reproduce this on the latest version please comment here with details and we can re-open |
I prefer to leave this open for now, I want to try and dig deeper to see if I can find what is causing it. |
can RestClientBuilder provide a method maxRetryTimes? |
I added FailureListener. RestClient.FailureListener() {
@Override
public void onFailure(HttpHost host) {
logger.warn("es host failed. host: {}", host);
}
} When it failed,the logger is below: |
hi @liudunxu the RestClient should not retry a request indefinitely. When a node fails, it will simply retry all the other nodes in the worst case, it should not retry the same node more than once for the same request. Sorry I didn't have time to dig into this yet, I will soon. I think that providing maxRetryTimes is not the right solution here, it shouldn't be necessary and if it is it's probably due to a bug. |
@javanna is this still a thing? |
@nik9000 potentially, no progress made :( |
Hi @liudunxu can you to check if the "cluster2-host1", "cluster2-host2" & "cluster2-host3" are reachable from the host where the mentioned script is running.I am not sure about the timeout related with the calls but you can give it a look.I am also checking it from my end. |
@mohitrajvardhan17 yes, the three es hosts are reachable.I think it may be something wrong with the es instance's load. I have checked the es instance‘s log,When the server is under full GC, the error occurs frequently. Then I expand the cluster to six instances.And now it seldom happens. |
Here is what I think needs to happen for this issue to trigger (tested on 5.4)
Add the below code to RestClientTest on the 5.4 branch and you should see StackOverflow
|
how to solve it? |
We are closing this for inactivity but will reopen if necessary. |
Elasticsearch version:
Elasticsearch 5.2.2
JVM version (java -version):
1.8
Description of the problem including expected versus actual behavior:
throws exception
I have no idea of the reason of this exception.Can anyone add a attribute "maxRetryTimes" to the RestClient or other way to solve this problem?
More Details
The text was updated successfully, but these errors were encountered: