nacos configuration center timeout issue: java.net.ConnectException: no available server, currentServerAddr

Keywords: Java Spring github Linux

1. Questions

In a project architecture, use the SpringCloud microservice architecture, which configures Alibaba-Cloud to use SpringCloud components. The Service Discovery and Configuration Center uses Alibaba's open source component nacos, nacos-server is deployed in the centos7.0 environment under linux. Each service starts with a connection to the nacos-server side. When nacos-server is deployed in a Linux environment, becauseFramework bug s arise due to network fluctuations, which are not a problem under Windows. When deployed on Linux, clients connect to the Configuration Center with the following errors and error logs:

2020-04-14 09:51:15.874 ERROR [jiuyv-gateway,,,] 15364 --- [252.80.198_8848] c.a.n.c.config.http.ServerHttpAgent      : [NACOS SocketTimeoutException httpPost] currentServerAddr: http://130.252.80.198:8848, err : Read timed out
2020-04-14 09:51:15.874 ERROR [jiuyv-gateway,,,] 15364 --- [252.80.198_8848] c.a.n.c.config.http.ServerHttpAgent      : no available server, currentServerAddr : http://130.252.80.198:8848
2020-04-14 09:51:16.049 ERROR [jiuyv-gateway,,,] 15364 --- [252.80.198_8848] c.a.n.client.config.impl.ClientWorker    : [fixed-130.252.80.198_8848] [check-update] get changed dataId exception

java.net.ConnectException: no available server, currentServerAddr : http://130.252.80.198:8848
	at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpPost(ServerHttpAgent.java:170) ~[nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpPost(MetricsHttpAgent.java:64) ~[nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateConfigStr(ClientWorker.java:377) [nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateDataIds(ClientWorker.java:352) [nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker$LongPollingRunnable.run(ClientWorker.java:512) [nacos-client-1.1.4.jar:na]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_25]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_25]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_25]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_25]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_25]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_25]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]

2020-04-14 09:51:16.052 ERROR [jiuyv-gateway,,,] 15364 --- [252.80.198_8848] c.a.n.client.config.impl.ClientWorker    : longPolling error : 

java.net.ConnectException: no available server, currentServerAddr : http://130.252.80.198:8848
	at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpPost(ServerHttpAgent.java:170) ~[nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpPost(MetricsHttpAgent.java:64) ~[nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateConfigStr(ClientWorker.java:377) ~[nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateDataIds(ClientWorker.java:352) ~[nacos-client-1.1.4.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker$LongPollingRunnable.run(ClientWorker.java:512) ~[nacos-client-1.1.4.jar:na]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_25]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_25]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_25]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_25]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_25]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_25]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]

Console screenshots are as follows:

2. Reasons

The reason is that due to some network latency due to the configuration on the remote server, the timeout time is set very short in the two nacos framework, and the timeout exception has been reported for a long time. Although this does not affect usage, the problem is still obvious. There is a bug in the framework. If the same configuration is started on the local nacos configuration center, the problem is not encountered.

3. Solutions

1. Check the source code and ask questions

After finding that this exception is a bug in the framework, look for the nacos source and see Issue: https://github.com/alibaba/nacos/issues/2206 To see if there is a similar problem, we found this timeout problem on GitHub, but there is no clear solution, just that it will be solved after the next 1.2.0 release, and that some people still have this problem because the client and server sides of nacos are upgraded to version 1.2.0. So I asked a question, and the answer on the official GitHub is as follows:

Issue: https://github.com/alibaba/nacos/issues/2206

2. Solution: pom joins nacos-client side dependency

    <!-- Alibaba-nacos Service Discovery-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!-- Alibaba-nacos Configuration Center-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.nacos</groupId>
            <artifactId>nacos-client</artifactId>
            <version>1.2.0</version>
        </dependency>

3. The version I use

  • Spring Boot Version: 2.1.6.RELEASE
  • Spring Cloud Version: Spring Cloud Greenwich
  • Spring Cloud Alibaba Version: 2.1.1.RELEASE
  • Nacos Version: 1.1.4
  • Java Version: 1.8

Through the above practice of integrating nacos into a microservice project as a service registration and discovery and configuration center, there are still some minor bug s. I believe that the nacos framework will be improved in the future updates, so we will experience its more experiential functions.

If you have any questions, please comment and contact me. I would like to discuss them.

338 original articles have been published. 237. Visits 810,000+
His message board follow

Posted by fatal on Fri, 17 Apr 2020 00:26:45 -0700