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

Questions about shutdown graceful #2865

Closed
2 tasks done
zonghaishang opened this issue Dec 2, 2018 · 3 comments
Closed
2 tasks done

Questions about shutdown graceful #2865

zonghaishang opened this issue Dec 2, 2018 · 3 comments

Comments

@zonghaishang
Copy link
Member

  • 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.0
  • Operating System version: mac
  • Java version: 1.8

org.apache.dubbo.config.AbstractConfig:

static {
    // this is only for compatibility
    Runtime.getRuntime().addShutdownHook(DubboShutdownHook.getDubboShutdownHook());
}

The jvm hook is registered by default. When the user uses spring, the default hook is not removed. It was the earliest cause of this shutdown graceful, mainly due to this reason. Please note:
Spring does not register hooks by default, but users may register themselves, spring-boot will also register hooks by default.

org.apache.dubbo.config.spring.extension.SpringExtensionFactory.ShutdownHookListener:

private static class ShutdownHookListener implements ApplicationListener {
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ContextClosedEvent) {
            // we call it anyway since dubbo shutdown hook make sure its destroyAll() is re-entrant.
            // pls. note we should not remove dubbo shutdown hook when spring framework is present, this is because
            // its shutdown hook may not be installed.
            DubboShutdownHook shutdownHook = DubboShutdownHook.getDubboShutdownHook();
            shutdownHook.destroyAll();
        }
    }
}
@zonghaishang
Copy link
Member Author

@beiwei30 @chickenlj Please take a look

@LiZhenNet
Copy link
Contributor

@beiwei30 @chickenlj Please take a look

I have pull a request about this。 you can take a look #2901

@zonghaishang
Copy link
Member Author

    public static void addApplicationContext(ApplicationContext context) {
        contexts.add(context);
+        Runtime.getRuntime().removeShutdownHook(DubboShutdownHook.getDubboShutdownHook());
        BeanFactoryUtils.addApplicationListener(context, shutdownHookListener);
    }

It looks good, close it now.

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

2 participants