You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ki...@apache.org on 2021/06/15 02:30:41 UTC

[dolphinscheduler] 02/12: [DS-5559][fix][Master Server] Master Server was shutdown but the process still in system (#5588)

This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch json_split_two
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit 3193837f5aeba440408243a84eba3a490602c18d
Author: Chouc <32...@users.noreply.github.com>
AuthorDate: Fri Jun 4 13:27:18 2021 +0800

    [DS-5559][fix][Master Server] Master Server was shutdown but the process still in system (#5588)
    
    * Close spring context to destory beans that has running thread
---
 .../org/apache/dolphinscheduler/server/master/MasterServer.java   | 2 ++
 .../dolphinscheduler/service/bean/SpringApplicationContext.java   | 8 ++++++++
 .../dolphinscheduler/service/zk/CuratorZookeeperClient.java       | 8 ++++++++
 3 files changed, 18 insertions(+)

diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java
index 016c8c9..6c15145 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java
@@ -183,6 +183,8 @@ public class MasterServer implements IStoppable {
             } catch (Exception e) {
                 logger.warn("Quartz service stopped exception:{}", e.getMessage());
             }
+            // close spring Context and will invoke method with @PreDestroy annotation to destory beans. like ServerNodeManager,HostManager,TaskResponseService,CuratorZookeeperClient,etc
+            springApplicationContext.close();
         } catch (Exception e) {
             logger.error("master server stop exception ", e);
         }
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/bean/SpringApplicationContext.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/bean/SpringApplicationContext.java
index 484b837..61dfcb3 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/bean/SpringApplicationContext.java
+++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/bean/SpringApplicationContext.java
@@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.service.bean;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -32,6 +33,13 @@ public class SpringApplicationContext implements ApplicationContextAware {
         SpringApplicationContext.applicationContext = applicationContext;
     }
 
+    /**
+     * Close this application context, destroying all beans in its bean factory.
+     */
+    public void close() {
+        ((AbstractApplicationContext)applicationContext).close();
+    }
+
     public static <T> T getBean(Class<T> requiredType) {
         return applicationContext.getBean(requiredType);
     }
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/CuratorZookeeperClient.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/CuratorZookeeperClient.java
index e25a22f..a437a63 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/CuratorZookeeperClient.java
+++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/CuratorZookeeperClient.java
@@ -27,6 +27,7 @@ import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.api.ACLProvider;
 import org.apache.curator.framework.state.ConnectionState;
 import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.utils.CloseableUtils;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.data.ACL;
 
@@ -34,6 +35,8 @@ import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import javax.annotation.PreDestroy;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.InitializingBean;
@@ -125,4 +128,9 @@ public class CuratorZookeeperClient implements InitializingBean {
     public CuratorFramework getZkClient() {
         return zkClient;
     }
+
+    @PreDestroy
+    public void close() {
+        CloseableUtils.closeQuietly(zkClient);
+    }
 }