簡體   English   中英

Elasticsearch RestClient 連接由對等方重置

[英]Elasticsearch RestClient Connection reset by peer

我的 AWS VPC 中有一個具有 2 個節點的 ES 集群。 在這些節點之上,我有一個負載均衡器。 在同一個 vpc 中,我有一個通過RestHighLevelClient版本 7.5.2 訪問 Elasticsearch 的微服務。

我以下列方式創建客戶端:

public class ESClientWrapper {

    @Getter
    private RestHighLevelClient client;

    public ESClientWrapper() throws IOException {
        FileInputStream propertiesFile = new FileInputStream("/var/elastic.properties");
        Properties properties = new Properties();
        properties.load(propertiesFile );
        RestClientBuilder builder = RestClient.builder(new HttpHost(
                properties .getProperty("host"),
                Integer.parseInt(properties.getProperty("port"))
        ));

        this.client = new RestHighLevelClient(builder);
    }
}

當我的微服務長時間(12 小時 ..)沒有收到請求時,發送的第一個響應(或之后的幾個..)會出現以下錯誤:

    2020-09-09 07:03:13.106  INFO 1 --- [nio-8080-exec-1] c.a.a.services.CustomersMetadataService  : Trying to add the following role : {role=a2}
2020-09-09 07:03:13.106  INFO 1 --- [nio-8080-exec-1] c.a.a.e.repositories.ESRepository        : Trying to insert the following document to app-index : {role=a2}
2020-09-09 07:03:13.109 ERROR 1 --- [nio-8080-exec-1] c.a.a.e.dal.ESRepository       : Failed to add customer : {role=a2}


java.io.IOException: Connection reset by peer
        at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:828) ~[elasticsearch-rest-client-7.5.2.jar!/:7.5.2]
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:248) ~[elasticsearch-rest-client-7.5.2.jar!/:7.5.2]
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235) ~[elasticsearch-rest-client-7.5.2.jar!/:7.5.2]
        at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1514) ~[elasticsearch-rest-high-level-client-7.5.2.jar!/:7.5.2]
        at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484) ~[elasticsearch-rest-high-level-client-7.5.2.jar!/:7.5.2]
        at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454) ~[elasticsearch-rest-high-level-client-7.5.2.jar!/:7.5.2]
        at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:871) ~[elasticsearch-rest-high-level-client-7.5.2.jar!/:7.5.2]
    ....
    ....
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.35.jar!/:9.0.35]
        at java.base/java.lang.Thread.run(Thread.java:836) ~[na:na]
Caused by: java.io.IOException: Connection reset by peer
        at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:na]
        at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[na:na]
        at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276) ~[na:na]
        at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:245) ~[na:na]
        at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223) ~[na:na]
        at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:358) ~[na:na]
        at org.apache.http.impl.nio.reactor.SessionInputBufferImpl.fill(SessionInputBufferImpl.java:231) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.codecs.AbstractMessageParser.fillBuffer(AbstractMessageParser.java:136) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:241) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.4.jar!/:4.1.4]
        at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.4.jar!/:4.1.4]
        at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) ~[httpcore-nio-4.4.13.jar!/:4.4.13]
        ... 1 common frames omitted

2020-09-09 07:06:55.109  INFO 1 --- [nio-8080-exec-2] c.a.a.services.MyService  : Trying to add the following role : {role=a2}
2020-09-09 07:06:55.109  INFO 1 --- [nio-8080-exec-2] c.a.a.e.repositories.ESRepository        : Trying to insert the following document to index app-index: {role=a2}
2020-09-09 07:06:55.211  INFO 1 --- [nio-8080-exec-2] c.a.a.e.dal.ESRepository       : IndexResponse[index=app-index,type=_doc,id=x532323272533321870287,version=1,result=created,seqNo=70,primaryTerm=1,shards={"total":2,"successful":2,"failed":0}]

如您所見,請求失敗 3 分鍾后,ES 成功處理了下一個請求。 什么可以殺死請求? 我檢查了 Elasticsearch 日志,沒有看到任何終止連接的跡象。 MS 與彈性位於同一 vpc 中,因此它不會通過任何可能殺死它的防火牆。

我在 github 中發現了以下問題,建議增加默認連接超時,但我想知道這里的問題是否真的是超時問題,如果增加默認時間真的是最好的解決方案..

另外,我發現這個 bug在他們的 repo 中打開了關於同樣的問題,但沒有任何答案。

更新我注意到,即使在 10 分鍾后我的服務已經啟動,這種情況也會發生。 我的服務啟動並向 ES 發送了一個查詢,一切運行良好。 10 分鍾后,我發送了插入請求,但在對等方重置連接時失敗。

最后我在我的配置/實現中沒有發現問題。 這似乎是 Elasticsearch 的 RestHighLevelClient 實現中的一個錯誤

我實現了一個重試機制,它包裝了 RestHighLevelClient 並在遇到相同的錯誤時重試查詢。 我在這個解決方案中使用了 Spring @Retry 注釋。

我面臨同樣的問題。 一切正常,但過了一段時間后,一個請求被拒絕了。

解決方案(在我的情況下)是將 tcp 連接的 keepalive 屬性設置為:

final RestClientBuilder restClientBuilder = RestClient.builder(...);
    
restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom()
                                .setSoKeepAlive(true)
                                .build()))

在這里找到: https : //github.com/elastic/elasticsearch/issues/65213

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM