一、问题分析和代码跟踪

原来跑的好好的代码,晚上运行的时候提示连接不上 zookeeper。提示信息如下:

java.lang.IllegalStateException: zookeeper not connected
	at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.<init>(CuratorZookeeperClient.java:83) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter.createZookeeperClient(CuratorZookeeperTransporter.java:26) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter.connect(AbstractZookeeperTransporter.java:70) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter$Adaptive.connect(ZookeeperTransporter$Adaptive.java) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport.<init>(ZookeeperMetadataReport.java:61) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReportFactory.createMetadataReport(ZookeeperMetadataReportFactory.java:37) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory.getMetadataReport(AbstractMetadataReportFactory.java:49) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.metadata.report.MetadataReportFactory$Adaptive.getMetadataReport(MetadataReportFactory$Adaptive.java) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.metadata.report.MetadataReportInstance.init(MetadataReportInstance.java:49) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.startMetadataReport(DubboBootstrap.java:630) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.initMetadataService(DubboBootstrap.java:716) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.initialize(DubboBootstrap.java:517) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:744) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextRefreshedEvent(DubboBootstrapApplicationListener.java:59) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:52) ~[dubbo-2.7.7.jar:2.7.7]
	at org.apache.dubbo.config.spring.context.OneTimeExecutionApplicationContextEventListener.onApplicationEvent(OneTimeExecutionApplicationContextEventListener.java:40) ~[dubbo-2.7.7.jar:2.7.7]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at com.tom.bootdubboorderprovider.BootDubboOrderProviderApplication.main(BootDubboOrderProviderApplication.java:12) [classes/:na]
Caused by: java.lang.IllegalStateException: zookeeper not connected
	at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.<init>(CuratorZookeeperClient.java:80) ~[dubbo-2.7.7.jar:2.7.7]
	... 30 common frames omitted

2020-06-29 23:20:58.928  INFO 5200 --- [           main] .b.c.e.AwaitingNonWebApplicationListener :  [Dubbo] Current Spring Boot Application is about to shutdown...
2020-06-29 23:20:58.935  INFO 5200 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-06-29 23:20:58.935  INFO 5200 --- [           main] f.a.ReferenceAnnotationBeanPostProcessor : class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!

Process finished with exit code 1

点开报错信息,跟踪进源码,发现异常的抛出是由于在等待连接返回时的返回值false

跟进方法,可以看到他在不断循环等待连接成功,若在最大等待时间内连接上,则返回true,否则false

综合所述,猜测是由于网络原因,超时所致(毕竟穷逼买的是100多块钱一年的服务器~~~)

 

二、继续深入

猜出了大概原因,如果是超时所致,且使用 dubbo-admin 发现 Zookeeper 运行状态正常,那么只要提高最大等待时间就可以了

根据关键字发现,可能跟 metadata-report 的设置有关,且 timeout 有个默认值 5 秒

继续跟踪,查找 CuratorZookeeperClient 方法的调用

结果很明显,这个 timeout 是从配置文件中读取出来的,若没有,则是 5000 ms

 

三、修改配置文件

# 设置最大等待时间为10秒
dubbo.metadata-report.timeout=10000

 

四、重试 => 翻车

重试依旧报错,查看

再去找配置文件

# 配置中心连接时间改为10秒
dubbo.config-center.timeout=10000

 

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐