zrlw commented on a change in pull request #8824:
URL: https://github.com/apache/dubbo/pull/8824#discussion_r710014603



##########
File path: 
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
##########
@@ -81,7 +85,11 @@ public void register() {
      */
     public void unregister() {
         if (registered.compareAndSet(true, false)) {
-            Runtime.getRuntime().removeShutdownHook(this);
+            try {
+                Runtime.getRuntime().removeShutdownHook(this);

Review comment:
       ShutdownHookCallbacks.callback() will be called:
   ```
   ##[error]Exception in thread "DubboShutdownHook" java.lang.RuntimeException: 
java.lang.IllegalStateException: Shutdown in progress
        at 
org.apache.dubbo.common.function.ThrowableAction.execute(ThrowableAction.java:48)
        at 
org.apache.dubbo.common.lang.ShutdownHookCallbacks.lambda$callback$0(ShutdownHookCallbacks.java:72)
        at java.lang.Iterable.forEach(Iterable.java:75)
        at 
org.apache.dubbo.common.lang.ShutdownHookCallbacks.callback(ShutdownHookCallbacks.java:72)
        at 
org.apache.dubbo.config.DubboShutdownHook.callback(DubboShutdownHook.java:89)
   ```
   you'd better add try-catch in ShutdownHookCallbacks callback() method like 
this, it will catch all callback exceptions including DubboShutdownHook 
unregister exception :
   ```
   ShutdownHookCallbacks.java:
       private static final Logger logger = 
LoggerFactory.getLogger(ShutdownHookCallbacks.class);
       public void callback() {
           getCallbacks().forEach(callback -> {
               try {
                   execute(callback::callback);
               } catch (Exception e) {
                   logger.warn("callback exception.", e);
               }
           });
       }
   ```




-- 
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]

Reply via email to