前言
dubbo 利用 curator 去连接 zookeeper 的时候,会需要比较长的时间,超过默认的(dubbo:registry:timeout),时间有点过长,应该是一个bug。暂时的解决方法是:把参数延长。
显示
Caused by: java.lang.IllegalStateException: zookeeper not connected
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.<init>(CuratorZookeeperClient.java:80) ~[dubbo-2.7.5.jar:2.7.5]
... 38 common frames omitted
网络抓包分析
在Dubbo消费者或提供者向zookeeper注册自己的时候,发起网络连接前会停顿很久。(红框部分是用于共享计算机名字和IP的报文,与本次讨论无关)。
初步结论:zookeeper 的客户端连接前有被阻塞的嫌疑
// ClientCnxn.java:930
setName(getName().replaceAll("\\(.*\\)",
"(" + addr.getHostName() + ":" + addr.getPort() + ")"));
//
2020-03-24 21:55:44.688 INFO 2824 --- [68.23.111:2181)] org.apache.zookeeper.ClientCnxn : Opening socket connection to server 192.168.23.111/192.168.23.111:2181.
最后问题定位到:
// InetAddress.java
private static String getHostFromNameService(InetAddress addr, boolean check) {
String host = null;
for (NameService nameService : nameServices) {
try {
// first lookup the hostname
// nameService 获取名称时过慢
host = nameService.getHostByAddr(addr.getAddress());
/* check to see if calling code is allowed to know
* the hostname for this IP address, ie, connect to the host
*/
if (check) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkConnect(host, -1);
}
}