zookeeper连接报某个节点connection loss
测试环境有一套zookeeper,使用各种客户端总是会报connection loss的问题,但是直接在机器上进行连接是就没问题。之前没当回事,以为是客户端的bug。现在使用zkui进行管理时,报/dubbo节点 connection loss的问题,没报其他节点的问题。zkui 是java客户端,可以直接使用源码进行调试,我就在报异常的地方加了try catch,在异常时进行跳过,然后zkui可以正常展示加载数据了。
因为是 /dubbo节点除的问题,所以我直接在机器上连接zk,然后对/dubbo节点进行读取get
和列表ls
操作,然后报出如下错误。
[zk: 127.0.0.1:2181(CONNECTED) 0] ls /dubbo
2022-08-02 12:10:19,859 [myid:] - WARN [main-SendThread(localhost:2181):ClientCnxn$SendThread@1164] - Session 0x100000333730010 for server localhost/127.0.0.1:2181, unexpected error, closing socket connection and attempting reconnect
java.io.IOException: Packet len4724847 is out of range!
at org.apache.zookeeper.ClientCnxnSocket.readLength(ClientCnxnSocket.java:113)
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:79)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:366)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /dubbo
at org.apache.zookeeper.KeeperException.create(KeeperException.java:102)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)
at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1541)
at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1569)
at org.apache.zookeeper.ZooKeeperMain.processZKCmd(ZooKeeperMain.java:732)
at org.apache.zookeeper.ZooKeeperMain.processCmd(ZooKeeperMain.java:600)
at org.apache.zookeeper.ZooKeeperMain.executeLine(ZooKeeperMain.java:372)
at org.apache.zookeeper.ZooKeeperMain.run(ZooKeeperMain.java:332)
at org.apache.zookeeper.ZooKeeperMain.main(ZooKeeperMain.java:291)
WATCHER::
WatchedEvent state:Disconnected type:None path:null
然后搜索 Packet len* is out of range!
问题相关的文档,大体逻辑就是,创建与zookeeper连接之后,要对某个节点进行读写操作,为了提高吞吐量,先判断下该节点数据量大小是否超过设置的jute.maxbuffer,如果是,就抛出异常。文档https://blog.csdn.net/liuxinghao/article/details/59071373
。文档中给出了解决方法:在创建zookeeper前,手动设置jute.maxbuffer
的值。
System.setProperty("jute.maxbuffer", 4096 * 1024 * 10 + "");
ZooKeeper zk = ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0], globalProps);
然后zkui的功能就正常使用了,问题解决。