dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

[Bug] Graceful Shutdown in dubbo-2.7.22 Has a Bug

Open qq664042 opened this issue 1 year ago • 7 comments

Pre-check

  • [X] I am sure that all the content I provide is in English.

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

2.7.22 However, I found that versions 2.7.7 through 2.7.23 all have this bug, while version 2.7.3 does not have this bug.

Steps to reproduce this issue

When integrating Dubbo 2.7.22 in a Spring Boot project, and using dubbo:reference in dubbo.xml similar to: <dubbo:reference interface="com.xdd.test.demo44.remote.IUserServiceRemote" id="userServiceRemote"/>

After starting the Spring Boot application, you will observe that the java.lang.ApplicationShutdownHooks.hooks variable contains an additional DubboShutdownHook object.

What you expected to happen

In the Dubbo consumer application, it can wait for the tasks to complete upon shutdown, up to a timeout of 10 seconds, rather than directly interrupting the tasks in progress.

Anything else

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean first executes DubboShutdownHook.getDubboShutdownHook().unregister(). During the process of setting properties for the bean, org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean then executes DubboShutdownHook.getDubboShutdownHook().register().

The order is reversed, causing the DubboShutdownHook to persist after the consumer starts. When the consumer stops, the DubboShutdownHook may execute before the SpringApplicationShutdownHook, directly shutting down tasks that haven't finished executing. This results in the "Interrupted unexpectedly while waiting for" exception. image

This bug also exists in dubbo-2.7.23. 企业微信截图_eb769e1c-6629-4441-a925-a0017cdff5e3

I seem to have seen a similar issue, but not in this version: https://github.com/apache/dubbo/issues/7093. My current solution is to directly call DubboShutdownHook.getDubboShutdownHook().unregister() after the Spring Boot application starts.

My English is not very good, but you can check the original link in Chinese: https://github.com/apache/dubbo/issues/14488

Are you willing to submit a pull request to fix on your own?

  • [X] Yes I am willing to submit a pull request on my own!

Code of Conduct

qq664042 avatar Aug 02 '24 01:08 qq664042

Please try upgrade to 3.2.x

AlbumenJ avatar Aug 07 '24 07:08 AlbumenJ

Already fixed in the latest version

AlbumenJ avatar Aug 07 '24 07:08 AlbumenJ

Already fixed in the latest version

Why not fix it in a minor version after 2.x

qq664042 avatar Aug 09 '24 06:08 qq664042

Already fixed in the latest version

Why not fix it in a minor version after 2.x

2.x has already EOL since May 2023

AlbumenJ avatar Aug 12 '24 01:08 AlbumenJ

If it has been resolved, please close the issue~

heliang666s avatar Aug 14 '24 15:08 heliang666s

How does 3.2.x fix this issue? I've found that my previous approach still had problems, and our team isn't ready to upgrade to 3.2.x just yet.

qq664042 avatar Aug 15 '24 01:08 qq664042

You can check DubboShutdownHook in the latest version

AlbumenJ avatar Aug 21 '24 01:08 AlbumenJ