yanghua commented on a change in pull request #6540: [FLINK-9891] Added hook to 
shutdown cluster if a session was created in per-job mode.
URL: https://github.com/apache/flink/pull/6540#discussion_r209443483
 
 

 ##########
 File path: 
flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
 ##########
 @@ -249,13 +250,24 @@ protected void run(String[] args) throws Exception {
                                        LOG.info("Could not properly shut down 
the client.", e);
                                }
                        } else {
+                               final ClusterShutdownHook shutdownHook;
                                if (clusterId != null) {
                                        client = 
clusterDescriptor.retrieve(clusterId);
+                                       shutdownHook = null;
                                } else {
                                        // also in job mode we have to deploy a 
session cluster because the job
                                        // might consist of multiple parts 
(e.g. when using collect)
                                        final ClusterSpecification 
clusterSpecification = customCommandLine.getClusterSpecification(commandLine);
                                        client = 
clusterDescriptor.deploySessionCluster(clusterSpecification);
+                                       // if not running in detached mode, add 
a shutdown hook to shut down cluster if client exits
+                                       // there's a race-condition here if cli 
is killed before shutdown hook is installed
+                                       if (!runOptions.getDetachedMode()) {
+                                               shutdownHook = new 
ClusterShutdownHook(client);
+                                               
Runtime.getRuntime().addShutdownHook(shutdownHook);
 
 Review comment:
   In flink-core there is a `ShutdownHookUtil` util class you can consider

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to