tweise commented on a change in pull request #13042:
URL: https://github.com/apache/flink/pull/13042#discussion_r465360429



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
##########
@@ -470,4 +479,30 @@ static String getTaskManagerResourceID(Configuration 
config, String rpcAddress,
                                        ? 
InetAddress.getLocalHost().getHostName() + "-" + new 
AbstractID().toString().substring(0, 6)
                                        : rpcAddress + ":" + rpcPort + "-" + 
new AbstractID().toString().substring(0, 6));
        }
+
+       /**
+        * If configured, registers a custom SecurityManager which forcefully 
exists the TaskManager instead of
+        * shutting it down gracefully via the registered ShutdownHooks.
+        *
+        * @param configuration The task manager configuration
+        */
+       private static void maybeOverrideShutdownLogic(Configuration 
configuration) {
+               boolean gracefulShutdown = 
configuration.get(GRACEFUL_SHUTDOWN_ON_ERROR);
+               if (gracefulShutdown) {
+                       // No need to setup a SecurityManager to deal with 
System.exit calls.
+                       return;
+               }
+               SecurityManager forcefulShutdownManager = new 
ExitTrappingSecurityManager(
+                       status -> Runtime.getRuntime().halt(status),
+                       System.getSecurityManager());
+               try {
+                       System.setSecurityManager(forcefulShutdownManager);
+               } catch (Exception e) {
+                       throw new IllegalConfigurationException(
+                               String.format("Could not register forceful 
shutdown handler for configuration '%s'. Either allow setting a SecurityManager 
or set the configuration to its default: '%s'",
+                                       GRACEFUL_SHUTDOWN_ON_ERROR.key(),
+                                       
GRACEFUL_SHUTDOWN_ON_ERROR.defaultValue()),
+                               e);

Review comment:
       I think that is an acceptable limitation since it is an optional 
feature. It would be good to document it as part of the configuration option.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to