Github user zsxwing commented on a diff in the pull request: https://github.com/apache/spark/pull/18357#discussion_r125817451 --- Diff: core/src/main/scala/org/apache/spark/util/SparkUncaughtExceptionHandler.scala --- @@ -20,29 +20,29 @@ package org.apache.spark.util import org.apache.spark.internal.Logging /** - * The default uncaught exception handler for Executors terminates the whole process, to avoid - * getting into a bad state indefinitely. Since Executors are relatively lightweight, it's better - * to fail fast when things go wrong. + * The default uncaught exception handler for Spark daemons. It terminates the whole process for + * any Errors, and also terminates the process for Exceptions when the exitOnException flag is true. */ -private[spark] object SparkUncaughtExceptionHandler +private[spark] class SparkUncaughtExceptionHandler(val exitOnException: Boolean = true) extends Thread.UncaughtExceptionHandler with Logging { override def uncaughtException(thread: Thread, exception: Throwable) { try { - // Make it explicit that uncaught exceptions are thrown when container is shutting down. + // Make it explicit that uncaught exceptions are thrown when process is shutting down. // It will help users when they analyze the executor logs - val inShutdownMsg = if (ShutdownHookManager.inShutdown()) "[Container in shutdown] " else "" - val errMsg = "Uncaught exception in thread " - logError(inShutdownMsg + errMsg + thread, exception) - - // We may have been called from a shutdown hook. If so, we must not call System.exit(). - // (If we do, we will deadlock.) - if (!ShutdownHookManager.inShutdown()) { + val errMsg = "Uncaught exception in thread " + thread + if (ShutdownHookManager.inShutdown()) { + logError("[Process in shutdown] " + errMsg, exception) + } else if (exception.isInstanceOf[Error] || + (!exception.isInstanceOf[Error] && exitOnException)) { + logError(errMsg + ". Shutting down now..", exception) if (exception.isInstanceOf[OutOfMemoryError]) { System.exit(SparkExitCode.OOM) } else { System.exit(SparkExitCode.UNCAUGHT_EXCEPTION) --- End diff -- The current changes are too much. Could you rename `exitOnException` to `exitOnUncaughtException` and just change this line to ``` if (exitOnUncaughtException) { System.exit(SparkExitCode.UNCAUGHT_EXCEPTION) } ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org