apache / apache/dubbo

[3.0] CuratorZookeeperClient zookeeper not connected的原因可能是前面已经结束的测试类没有关闭zkClient所致

Open
#8,993 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

* Dubbo version: 3.0
搜zookeeper not connected可以搜到很多issue,现在github构建依然有:
(更新2021-10-12: 翻看了很多github构建失败的日志,发现每个抛zookeeper not connected异常的测试类之前都有其他测试类完成后并没有关闭zkClient的情况,这些依然存活的连接session依旧不停地尝试重连zk Server, PR #9003 几次构建日志里均没有出现过类似的情况,非常怀疑就是zkClient没有正常关闭导致的问题,看了3.6的ClientCnxn代码,sendThread的run方法会不停地调用clientCnxnSocket.doTransport尝试重新连接,但是因为测试类已结束,zk server早就关闭了,所以每次捕获异常,写Attempting reconnect except it is a SessionExpiredException日志,然后cleanAndNotifyState去调用eventThread.queueEvent发事件,因为这个是死循环,所以event队列应该会被很快充满掉,后续测试类的zk已连接事件挤不进去处理)
```
2021-10-08T07:35:43.7080332Z [ERROR] integrate Time elapsed: 4.058 s <<< ERROR!
2021-10-08T07:35:43.7081792Z java.lang.IllegalStateException: java.lang.IllegalStateException: zookeeper not connected
2021-10-08T07:35:43.7087481Z at org.apache.dubbo.integration.single.SingleRegistryCenterDubboProtocolIntegrationTest.integrate(SingleRegistryCenterDubboProtocolIntegrationTest.java:138)
```
问题原因看起来很简单,设置的超时时间短,CuratorZookeeperClient构造函数执行client.blockUntilConnected(timeout, TimeUnit.MILLISECONDS)就超时了。
AbstractZookeeperClient的DEFAULT_CONNECTION_TIMEOUT_MS是5000ms,实际上这个默认值用不上,url不设置timeout就会被ConfigCenterConfig的checkDefault方法设为3000ms。
下面是debug SingleRegistryCenterDubboProtocolIntegrationTest的调用栈:
```
ConfigCenterConfig.checkDefault() line: 128 <=== timeout为null时设为3000
ConfigCenterConfig(AbstractConfig).postProcessRefresh() line: 714
ConfigCenterConfig(AbstractConfig).refresh() line: 620
DefaultApplicationDeployer.startConfigCenter() line: 253
DefaultApplicationDeployer.initialize() line: 195
DefaultApplicationDeployer.start() line: 538
DubboBootstrap.start(boolean) line: 230
DubboBootstrap.start() line: 220
```
checkDefault代码片段:
```
protected void checkDefault() {
super.checkDefault();

if (namespace == null) {
namespace = CommonConstants.DUBBO;
}
if (group == null) {
group = CommonConstants.DUBBO;
}
if (timeout == null) {
timeout = 3000L;
}
...
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.