这几天写测试用例,测试的时候出了error
java.lang.IllegalStateException: instance must be started before calling this method
分析下原因本地测试的时候引用了dubbo服务,注册中心用的zk,zk 客户端使用的是 Apache 的 Curator
具体问题栈如下
java.lang.IllegalStateException: instance must be started before calling this method at org.apache.curator.shaded.com.google.common.base.Preconditions.checkState(Preconditions.java:176) ~[curator-client-2.13.0.jar:na]
at org.apache.curator.framework.imps.CuratorFrameworkImpl.getData(CuratorFrameworkImpl.java:375) ~[curator-framework-2.13.0.jar:na]
at org.apache.curator.framework.recipes.cache.TreeCache$TreeNode.doRefreshData(TreeCache.java:269) ~[curator-recipes-2.13.0.jar:na]
at org.apache.curator.framework.recipes.cache.TreeCache$TreeNode.refreshData(TreeCache.java:253) ~[curator-recipes-2.13.0.jar:na]
at org.apache.curator.framework.recipes.cache.TreeCache$TreeNode.process(TreeCache.java:349) ~[curator-recipes-2.13.0.jar:na]
at org.apache.curator.framework.imps.NamespaceWatcher.process(NamespaceWatcher.java:62) ~[curator-framework-2.13.0.jar:na]
at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:530) ~[zookeeper-3.4.8.jar:3.4.8--1]
at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:505) ~[zookeeper-3.4.8.jar:3.4.8--1]
2021-07-28 20:56:59.612 INFO 16596 --- [ain-EventThread] org.apache.zookeeper.ClientCnxn : EventThread shut down for session: 0x17ae7370b350bc1
Process finished with exit code 0
后面测试的时候又能正常运行
问题出在这个地方
bboShutdownHook
涉及dubbo优雅停机的问题,需要满足
- 新的请求不能再发往正在停机的 Dubbo 服务提供者。
- 若关闭服务提供者,已经接收到服务请求,需要处理完毕才能下线服务。
- 若关闭服务消费者,已经发出的服务请求,需要等待响应返回。
结合自身情况分析
1、zk在的那台机器性能过差(这次为了应用迷你化分配了很低的机器性能有时候60000的超时都不够)
2、 业务组内有人和我一起再调用那个dubbo的服务