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



##########
File path: 
flink-core/src/main/java/org/apache/flink/configuration/TaskManagerOptions.java
##########
@@ -79,6 +79,16 @@
                        .defaultValue(false)
                        .withDescription("Whether to kill the TaskManager when 
the task thread throws an OutOfMemoryError.");
 
+       /**
+        * Whether the task manager should attempt to gracefully shutdown 
itself on errors.
+        */
+       @Documentation.Section(Documentation.Sections.ALL_TASK_MANAGER)
+       public static final ConfigOption<Boolean> GRACEFUL_SHUTDOWN_ON_ERROR =
+               key("taskmanager.graceful-shutdown-on-error")

Review comment:
       I think it would be nice to make this behaviour configurable for all 
Flink processes.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/security/ExitTrappingSecurityManagerTest.java
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.security;
+
+import org.junit.Test;
+
+import java.security.Permission;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/** Unit tests for {@link ExitTrappingSecurityManager}. */
+public class ExitTrappingSecurityManagerTest {

Review comment:
       `extends TestLogger` is missing.

##########
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:
       What if some corporate policies does not allow to install a custom 
`SecurityManager`?




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