mxm commented on a change in pull request #13042:
URL: https://github.com/apache/flink/pull/13042#discussion_r464480958
##########
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:
That is indeed a limitation of this approach. The default behavior
doesn't require installing a security manager but to use the forceful shutdown
feature, we need permission to add a security manager. The situation is similar
for `Thread.setDefaultUncaughtExceptionHandler` because it also needs
permission from the `SecurityManager`. Arguably, maybe that's a less
restrictive permission.
----------------------------------------------------------------
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:
[email protected]