liuzhiguo630 opened a new issue, #10652: URL: https://github.com/apache/dubbo/issues/10652
- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate. ### Environment * Dubbo version: 3.1.0 * Java version: 1.8.0 ### Steps to reproduce this issue 1. 在 Spring Boot 环境下启动 Dubbo Provider 应用 2. 启动 Dubbo Consumer 并发持续调用 Provider 应用 3. kill 该进程 ### Expected Behavior 像文档说的那样可以优雅停机 ### Actual Behavior 实际情况是会报一大堆异常,并将异常返回至 Consumer 端。异常内容大多是: ``` [ERROR][2022-09-18 15:52:05.826][tri-protocol-20881-thread-200][org.apache.dubbo.rpc.filter.ExceptionFilter] [DUBBO] Got unchecked and undeclared exception which called by 172.17.0.221. service: cn.jojo.api.service.bs.ms.IMediaService, method: getEditMediaResult, exception: java.lang.IllegalStateException: ExtensionDirector is destroyed, dubbo version: 3.1.0, current host: 172.17.0.28 ``` ### 问题根因 Dubbo 的优雅停机实际上有两种机制: 1. Spring Boot 环境下 `DubboDeployApplicationListener#onContextClosedEvent` 监听到 `ContextClosedEvent` 时执行停机。 2. DubboShutdownHook 监听 JVM 的 shutdownHook 这两种机制同时运行时,会导致相互冲突,上边提到的报错`ExtensionDirector is destroyed`就是因为 DubboShutdownHook 关闭了 `ExtensionDirector` 导致的。 ### 解决办法 在经过反复测试后,只保留 `DubboDeployApplicationListener` 事件监听机制,是可以实现优雅停机的,而 `DubboShutdownHook` 的停机实际上并不优雅,它只是停机而已,甚至用不到 `dubbo.service.shutdown.wait` 参数,这个参数是通过 `DubboDeployApplicationListener` 监听事件最后走到 `RegistryProtocol` 中实现的。 建议在 Spring Boot 环境下默认关闭注册 `DubboShutdownHook`。 ### 另一个问题 `DubboShutdownHook` 提供了参数 `dubbo.shutdownHook.listenIgnore` 来阻止注册 JVM shutdownHook,但是这个参数是在类构造器中初始化的,而这个类的构造器又调用太早,导致读不到配置中心的配置,连 Spring Boot 配置也读不到,只有添加启动参数 `-Ddubbo.shutdownHook.listenIgnore=true` 才行。 而添加启动参数在规模稍大一些的系统中,是很难做到的,大家都是用配置中心来统一管理配置。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
