You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by pn...@apache.org on 2021/10/08 08:01:18 UTC

[flink] 04/10: [FLINK-24182][task] Unify exception preProcessing logic

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

pnowojski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit bc1b50f31d5180b65fdff7c6b18bdd73c01d4ea7
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Mon Sep 20 09:40:05 2021 +0200

    [FLINK-24182][task] Unify exception preProcessing logic
---
 .../org/apache/flink/runtime/taskmanager/Task.java | 58 ++++++++++++----------
 1 file changed, 33 insertions(+), 25 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
index 6aeb01a..eb75c4d 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
@@ -776,38 +776,14 @@ public class Task
                 throw new CancelTaskException();
             }
         } catch (Throwable t) {
-
-            // unwrap wrapped exceptions to make stack traces more compact
-            if (t instanceof WrappingRuntimeException) {
-                t = ((WrappingRuntimeException) t).unwrap();
-            }
-
             // ----------------------------------------------------------------
             // the execution failed. either the invokable code properly failed, or
             // an exception was thrown as a side effect of cancelling
             // ----------------------------------------------------------------
 
-            TaskManagerExceptionUtils.tryEnrichTaskManagerError(t);
+            t = preProcessException(t);
 
             try {
-                // check if the exception is unrecoverable
-                if (ExceptionUtils.isJvmFatalError(t)
-                        || (t instanceof OutOfMemoryError
-                                && taskManagerConfig.shouldExitJvmOnOutOfMemoryError())) {
-
-                    // terminate the JVM immediately
-                    // don't attempt a clean shutdown, because we cannot expect the clean shutdown
-                    // to complete
-                    try {
-                        LOG.error(
-                                "Encountered fatal error {} - terminating the JVM",
-                                t.getClass().getName(),
-                                t);
-                    } finally {
-                        Runtime.getRuntime().halt(-1);
-                    }
-                }
-
                 // transition into our final state. we should be either in DEPLOYING, INITIALIZING,
                 // RUNNING, CANCELING, or FAILED
                 // loop for multiple retries during concurrent state changes via calls to cancel()
@@ -910,6 +886,36 @@ public class Task
         }
     }
 
+    /** Unwrap, enrich and handle fatal errors. */
+    private Throwable preProcessException(Throwable t) {
+        // unwrap wrapped exceptions to make stack traces more compact
+        if (t instanceof WrappingRuntimeException) {
+            t = ((WrappingRuntimeException) t).unwrap();
+        }
+
+        TaskManagerExceptionUtils.tryEnrichTaskManagerError(t);
+
+        // check if the exception is unrecoverable
+        if (ExceptionUtils.isJvmFatalError(t)
+                || (t instanceof OutOfMemoryError
+                        && taskManagerConfig.shouldExitJvmOnOutOfMemoryError())) {
+
+            // terminate the JVM immediately
+            // don't attempt a clean shutdown, because we cannot expect the clean shutdown
+            // to complete
+            try {
+                LOG.error(
+                        "Encountered fatal error {} - terminating the JVM",
+                        t.getClass().getName(),
+                        t);
+            } finally {
+                Runtime.getRuntime().halt(-1);
+            }
+        }
+
+        return t;
+    }
+
     private void restoreAndInvoke(TaskInvokable finalInvokable) throws Exception {
         try {
             // switch to the INITIALIZING state, if that fails, we have been canceled/failed in the
@@ -1159,6 +1165,8 @@ public class Task
 
     @VisibleForTesting
     void cancelOrFailAndCancelInvokableInternal(ExecutionState targetState, Throwable cause) {
+        cause = preProcessException(cause);
+
         while (true) {
             ExecutionState current = executionState;