Skip to content

Commit

Permalink
[FLINK-30299][core] Adds thread dump creation to FatalExitExceptionHa…
Browse files Browse the repository at this point in the history
…ndler

Signed-off-by: Matthias Pohl <[email protected]>
  • Loading branch information
XComp committed Dec 20, 2022
1 parent 9633337 commit 49146cd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.flink.util;

import org.apache.flink.core.security.FlinkSecurityManager;
import org.apache.flink.util.concurrent.ThreadUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -43,6 +44,7 @@ public void uncaughtException(Thread t, Throwable e) {
"FATAL: Thread '{}' produced an uncaught exception. Stopping the process...",
t.getName(),
e);
ThreadUtils.errorLogThreadDump(LOG);
} finally {
FlinkSecurityManager.forceProcessExit(EXIT_CODE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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:https://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.util.concurrent;

import org.slf4j.Logger;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.util.Arrays;
import java.util.stream.Collectors;

/** {@code ThreadUtils} collects helper methods in the context of threading. */
public class ThreadUtils {

public static void errorLogThreadDump(Logger logger) {
final ThreadInfo[] perThreadInfo =
ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
logger.error(
"Thread dump: \n{}",
Arrays.stream(perThreadInfo).map(Object::toString).collect(Collectors.joining()));
}
}

0 comments on commit 49146cd

Please sign in to comment.