Elasticsearch出现Connection reset by peer

Elasticsearch出现Connection reset by peer分析

 

1.异常:

2024-06-13 13:17:10.539 WARN [http-nio-30411-exec-9]com.longdaotech.config.ESConfig -onFailure node:[host=http://192.168.239.253:9200]

2024/6/13 13:17:10 2024-06-13 13:17:10.541 WARN [http-nio-30411-exec-9]com.longdaotech.config.ESConfig -onFailure node:[host=http://192.168.239.249:9200]

2024/6/13 13:17:10 2024-06-13 13:17:10.542 WARN [http-nio-30411-exec-9]com.longdaotech.config.ESConfig -onFailure node:[host=http://192.168.239.67:9200]

2024/6/13 13:17:10 2024-06-13 13:17:10.543 ERROR [http-nio-30411-exec-9]com.longdaotech.front.modules.service.impl.GoodsSearchServiceImpl -{"monitorCode":"ESnull500601","message":"商品索引查询失败","contextContent":""}

2024/6/13 13:17:10 java.io.IOException: Connection reset by peer

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:793)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:218)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:221)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:221)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:930)

2024/6/13 13:17:10 at com.longdaotech.front.modules.service.impl.GoodsSearchServiceImpl.goodsSerarch(GoodsSearchServiceImpl.java:361)

2024/6/13 13:17:10 at com.longdaotech.front.modules.controller.GoodsSearchController.searchGoods(GoodsSearchController.java:107)

2024/6/13 13:17:10 at sun.reflect.GeneratedMethodAccessor326.invoke(Unknown Source)

2024/6/13 13:17:10 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

2.分析

  为什么服务端会关闭链接?

服务器会有TCP的Keepalive 经过一段时间如果没有操作就会自动断开连接功能,而ES默认就是取服务器的时长配置

linux查看超时时间默认为两小时

注:当ES服务端的keepAlive短于ES客户端的keepAlive,也会导致:服务端已经关闭了连接,客户端继续复用该连接,抛出异常。

3.解决

手动设置KeepAliveStrategy来配置keepAlive,保证客户端keepAlive小于服务端keepAlive,让客户端先于服务端关闭连接 

# 查看服务器超时时间(单位秒)
cat /proc/sys/net/ipv4/tcp_keepalive_time

默认是7200s

解决办法有两个,一是设置keepalive小于服务器的超时时间,这样HttpClient会自己断开连接,下次再重连,由于SpringBoot没有提供设置改属性的地方,配置起来有点小麻烦,可以参考以下链接

ES ElasticSearch Connection reset by peer问题解决_阿里巴巴首席技术官的博客-CSDN博客

方案二是发送心跳,下面贴出代码

@Scheduled(fixedRate = 60 * 1000 * 5)
public void heartbeatToES() {
    try {
        RequestOptions requestOptions = RequestOptions.DEFAULT.toBuilder().build();
        boolean result = restTemplate.getClient().ping(requestOptions);
        log.info("es状态: {}", result);
    } catch (Exception e) {

    }
}

方案二 设置ES服务端 tcp_keepalive_time时间大于等于客户端时间

https://blog.csdn.net/weixin_42195284/article/details/122399262








                        
ES ElasticSearch Connection reset by peer问题解决_es connection reset by peer-CSDN博客

  • 19
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Connection reset by peer是指由于对端(peer)的连接被重置而导致的连接错误。该错误通常伴随着ClientAbortException: java.io.IOException: Broken pipe的出现。在采集Metrics发送至ES的过程中,可能会出现在单数整点时正常发送,而在双数整点时发送失败的情况。这可能是因为esClient自动设置的KeepAlive时间为-1,即持续连接,而受到外界因素(如Firewall)的影响导致了TCP连接的单方面断开,从而引发了Connection reset by peer的错误。解决这个问题的方法是调整esClient的KeepAlive时间,确保连接在适当的时间内保持活动状态。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ES报错:Connection reset by peer 解决经历](https://blog.csdn.net/qq_27327261/article/details/119995930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [Connection reset by peer -- 客户端非正常中断连接](https://blog.csdn.net/tobrainto/article/details/127037321)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值