首页 > 其他分享 >Nacos启动:[NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reache

Nacos启动:[NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reache

时间:2023-12-19 10:33:08浏览次数:24  
标签:HTTP serverListMgr currentServerAddr maximum server NACOS maxRetry reconnection

一、表象

image.png

二、分析

源码:

public HttpRestResult<String> httpPost(String path, Map<String, String> headers, Map<String, String> paramValues,
            String encode, long readTimeoutMs) throws Exception {
    final long endTime = System.currentTimeMillis() + readTimeoutMs;
    injectSecurityInfo(paramValues);
    String currentServerAddr = serverListMgr.getCurrentServerAddr();
    int maxRetry = this.maxRetry;
    HttpClientConfig httpConfig = HttpClientConfig.builder()
        .setReadTimeOutMillis(Long.valueOf(readTimeoutMs).intValue())
        .setConTimeOutMillis(ConfigHttpClientManager.getInstance().getConnectTimeoutOrDefault(3000)).build();
    do {

        try {
            Header newHeaders = getSpasHeaders(paramValues, encode);
            if (headers != null) {
                newHeaders.addAll(headers);
            }
            HttpRestResult<String> result = NACOS_RESTTEMPLATE
                .postForm(getUrl(currentServerAddr, path), httpConfig, newHeaders, paramValues, String.class);

            // 错误码 HTTP_INTERNAL_ERROR = 500 || HTTP_BAD_GATEWAY = 502 || HTTP_UNAVAILABLE = 503 为异常
            if (isFail(result)) {
                LOGGER.error("[NACOS ConnectException] currentServerAddr: {}, httpCode: {}", currentServerAddr,
                             result.getCode());
            } else {
                // Update the currently available server addr
                serverListMgr.updateCurrentServerAddr(currentServerAddr);
                // 应从这里返回,否则会进入重试
                return result;
            }
        } catch (ConnectException connectException) {
            LOGGER.error("[NACOS ConnectException httpPost] currentServerAddr: {}, err : {}", currentServerAddr,
                         connectException.getMessage());
        } catch (SocketTimeoutException socketTimeoutException) {
            LOGGER.error("[NACOS SocketTimeoutException httpPost] currentServerAddr: {}, err : {}",
                         currentServerAddr, socketTimeoutException.getMessage());
        } catch (Exception ex) {
            LOGGER.error("[NACOS Exception httpPost] currentServerAddr: " + currentServerAddr, ex);
            throw ex;
        }

        // 重试逻辑
        if (serverListMgr.getIterator().hasNext()) {
            currentServerAddr = serverListMgr.getIterator().next();
        } else {
            // maxRetry = 3
            maxRetry--;
            if (maxRetry < 0) {
                throw new ConnectException(
                    "[NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reached");
            }
            serverListMgr.refreshCurrentServerAddr();
        }

    } while (System.currentTimeMillis() <= endTime);

    LOGGER.error("no available server, currentServerAddr : {}", currentServerAddr);
    throw new ConnectException("no available server, currentServerAddr : " + currentServerAddr);
}

image.png

三、解决

将配置文件application.yml更改为bootstrap.yml

标签:HTTP,serverListMgr,currentServerAddr,maximum,server,NACOS,maxRetry,reconnection
From: https://www.cnblogs.com/meidanlong/p/17913125.html

相关文章

  • HTTP事件流 text/event-stream
    GitHubAll-in-oneOpenAIDemo一、依赖<dependency><groupId>org.asynchttpclient</groupId><artifactId>async-http-client</artifactId><version>2.12.3</version></dependency>二、事件流处理器@Slf4jpublicclass......
  • HTTP事件流 text/event-stream
    GitHubAll-in-oneOpenAIDemo一、依赖<dependency><groupId>org.asynchttpclient</groupId><artifactId>async-http-client</artifactId><version>2.12.3</version></dependency>二、事件流处理器@Slf4jpublicclass......
  • wgcloud运维部署 - 配置使用https证书
    https://www.wgstart.com/help/docs137.html......
  • Istio从入门到精通—— 流量治理的原理 —— VirutalService —— HTTPRedirect
    流量治理的原理——VirutalService——HTTPRedirecthttps://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRedirect HTTPRedirectcanbeusedtosenda301redirectresponsetothecaller,wheretheAuthority/HostandtheURIinthe......
  • HTTP 3.0之QUIC优势和TCP弊端
    1HTTP3.01.1引言从HTTP/1.1到HTTP/2,HTTP协议一直都是使用TCP作为传输协议。然而,就在最新的HTTP/3,HTTP就直接把TCP抛弃了,向孤立无援的UDP伸出了援手,基于UDP协议的基础上,在应用层实现了一个可靠的传输协议——QUIC。很多同学可能就好奇了,HTTP都用TCP都用了几......
  • boost beast http::read 一直阻塞不返回,问题解决, 使用parser对象的skip(true) 来解
    用beast作为客户端发送http请求后读web服务端返回的数据,遇到了http::read或http::async_read一直阻塞着,不返回,直到连接过期后被强制网络断开后read函数才返回。看了官方文档,文档里这么描述的,read要一直等到end_of_stream时才回退出阻塞状态。也就是连接失效后才行。但我们的......
  • SpringBoot异步任务获取HttpServletRequest
     前言在使用框架日常开发中需要在controller中进行一些异步操作减少请求时间,但是发现在使用@Anysc注解后会出现Request对象无法获取的情况,本文就此情况给出完整的解决方案原因分析@Anysc注解会开启一个新的线程,主线程的Request和子线程是不共享的,所以获取为null在使用spr......
  • 关于python http.server 开启多线程并发的问题
    问题描述thon中的http.server模块是单线程的,这意味着它一次只能处理一个请求,而其他请求必须等待。为了解决这个问题,您可以考虑使用多线程或异步处理来处理并发请求。您可以使用Python的ThreadingMixIn来创建一个支持多线程的HTTP服务器,或者考虑使用异步框架如asyncio来处理请求......
  • 下载镜像提示 output: Error response from daemon: Get https://k8s.gcr.io/v2/: x5
    出现这问题可能是两种原因:1、k8s所有节点的时间不统一。2、k8s配置文件镜像仓库有问题问题:[root@master1~]#kubeadmconfigimagespull--configkubeadm-config.yamlW092001:12:10.7940302723configset.go:202]WARNING:kubeadmcannotvalidatecomponentconfigs......
  • 解决k8s Get http://127.0.0.1:10252/healthz: dial tcp 127.0.0.1:10252: connect: c
    安装完k8s集群之后很可能会出现一下情况:[root@master1~]#kubectlgetcsNAMESTATUSMESSAGEERRORschedulerUnhealthyGethttp://127.0.0.1:10251......