Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【dubbo优雅关机】关于spring管理的应用重复监听处理dubbo关闭。 #7093

Closed
2 tasks
oaoit opened this issue Jan 10, 2021 · 0 comments
Closed
2 tasks

Comments

@oaoit
Copy link
Contributor

oaoit commented Jan 10, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.7
  • Operating System version: mac os big sur
  • Java version: 1.8

Steps to reproduce this issue

  1. 使用spring boot内置容器启动应用。
  2. 使用kill pid关闭应用

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

dubbo彻底关闭(提示DubboBootstrap is about to shutdown...)后再关闭数据库连接池,这样给没有处理完的dubbo线程使用数据库连接的机会。

Actual Result

dubbo没有关闭完,数据库连接池已经关闭,导致应用并发高的时候很多没跑完的dubbo线程拿不到数据库连接抛出异常。

If there is an exception, please attach the exception trace:

msg:DUBBO服务异常 remoteHost:xxx.xx.xxx.xxx service:com.xxx.service.xxxService method:xxx message:nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-1) has been closed.

原因是spring管理的应用dubbo启动的时候同时开启了两个关闭dubbo服务的入口,一个在DubboBootstrap中
image
另外一个是DubboBootstrapApplicationListener中通过监听spring的关闭事件来关闭dubbo服务
image

数据源关闭是spring关机钩子处理。
通过DubboBootstrap注册的DubboShutdownHook是单独的一个线程,不与spring关机钩子阻塞执行,spring发送ContextClosedEvent后会继续执行关闭数据源连接池的动作。
image

通过监听ContextClosedEvent是使用的spring的关机钩子线程,会阻塞执行关闭dubbo后再继续执行关闭数据源连接池的动作。
image

临时解决方法:
通过在spring启动的方法中显示调用DubboBootstrap.getInstance().unRegisterShutdownHook();关闭DubboBootstrap自动注册的DubboShutdownHook。只保留监听ContextClosedEvent关闭dubbo服务。

优雅处理探讨:
是否不应该在DubboBootstrap创建的时候注册DubboShutdownHook。或者在SpringExtensionFactory中判断注册了spring的关机钩子就调用DubboBootstrap.getInstance().unRegisterShutdownHook();关闭DubboBootstrap自动注册的DubboShutdownHook。查看SpringExtensionFactory中历史代码,以前是类似的做法,在dubbo2.7.5版本去掉了。去掉设计参考#5504

xiaoheng1 added a commit to xiaoheng1/incubator-dubbo that referenced this issue Mar 3, 2021
xiaoheng1 added a commit to xiaoheng1/incubator-dubbo that referenced this issue Mar 21, 2021
xiaoheng1 added a commit to xiaoheng1/incubator-dubbo that referenced this issue Mar 21, 2021
xiaoheng1 added a commit to xiaoheng1/incubator-dubbo that referenced this issue Mar 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant