File tree Expand file tree Collapse file tree 6 files changed +17
-10
lines changed
core/src/main/scala/org/apache/spark
resource-managers/mesos/src/main/scala/org/apache/spark/deploy/mesos Expand file tree Collapse file tree 6 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ import org.apache.spark.internal.Logging
36
36
import org .apache .spark .metrics .MetricsSystem
37
37
import org .apache .spark .rpc ._
38
38
import org .apache .spark .serializer .{JavaSerializer , Serializer }
39
- import org .apache .spark .util .{ThreadUtils , Utils }
39
+ import org .apache .spark .util .{SparkUncaughtExceptionHandler , ThreadUtils , Utils }
40
40
41
41
private [deploy] class Master (
42
42
override val rpcEnv : RpcEnv ,
@@ -1045,6 +1045,8 @@ private[deploy] object Master extends Logging {
1045
1045
val ENDPOINT_NAME = " Master"
1046
1046
1047
1047
def main (argStrings : Array [String ]) {
1048
+ Thread .setDefaultUncaughtExceptionHandler(new SparkUncaughtExceptionHandler (
1049
+ exitOnUncaughtException = false ))
1048
1050
Utils .initDaemon(log)
1049
1051
val conf = new SparkConf
1050
1052
val args = new MasterArguments (argStrings, conf)
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ import org.apache.spark.deploy.worker.ui.WorkerWebUI
38
38
import org .apache .spark .internal .Logging
39
39
import org .apache .spark .metrics .MetricsSystem
40
40
import org .apache .spark .rpc ._
41
- import org .apache .spark .util .{ThreadUtils , Utils }
41
+ import org .apache .spark .util .{SparkUncaughtExceptionHandler , ThreadUtils , Utils }
42
42
43
43
private [deploy] class Worker (
44
44
override val rpcEnv : RpcEnv ,
@@ -737,6 +737,8 @@ private[deploy] object Worker extends Logging {
737
737
val ENDPOINT_NAME = " Worker"
738
738
739
739
def main (argStrings : Array [String ]) {
740
+ Thread .setDefaultUncaughtExceptionHandler(new SparkUncaughtExceptionHandler (
741
+ exitOnUncaughtException = false ))
740
742
Utils .initDaemon(log)
741
743
val conf = new SparkConf
742
744
val args = new WorkerArguments (argStrings, conf)
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ private[spark] class Executor(
56
56
env : SparkEnv ,
57
57
userClassPath : Seq [URL ] = Nil ,
58
58
isLocal : Boolean = false ,
59
- uncaughtExceptionHandler : UncaughtExceptionHandler = SparkUncaughtExceptionHandler )
59
+ uncaughtExceptionHandler : UncaughtExceptionHandler = new SparkUncaughtExceptionHandler )
60
60
extends Logging {
61
61
62
62
logInfo(s " Starting executor ID $executorId on host $executorHostname" )
Original file line number Diff line number Diff line change @@ -20,11 +20,12 @@ package org.apache.spark.util
20
20
import org .apache .spark .internal .Logging
21
21
22
22
/**
23
- * The default uncaught exception handler for Executors terminates the whole process, to avoid
24
- * getting into a bad state indefinitely. Since Executors are relatively lightweight, it's better
25
- * to fail fast when things go wrong.
23
+ * The default uncaught exception handler for Spark daemons. It terminates the whole process for
24
+ * any Errors, and also terminates the process for Exceptions when the exitOnException flag is true.
25
+ *
26
+ * @param exitOnUncaughtException Whether to exit the process on UncaughtException.
26
27
*/
27
- private [spark] object SparkUncaughtExceptionHandler
28
+ private [spark] class SparkUncaughtExceptionHandler ( val exitOnUncaughtException : Boolean = true )
28
29
extends Thread .UncaughtExceptionHandler with Logging {
29
30
30
31
override def uncaughtException (thread : Thread , exception : Throwable ) {
@@ -40,7 +41,7 @@ private[spark] object SparkUncaughtExceptionHandler
40
41
if (! ShutdownHookManager .inShutdown()) {
41
42
if (exception.isInstanceOf [OutOfMemoryError ]) {
42
43
System .exit(SparkExitCode .OOM )
43
- } else {
44
+ } else if (exitOnUncaughtException) {
44
45
System .exit(SparkExitCode .UNCAUGHT_EXCEPTION )
45
46
}
46
47
}
Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ private[spark] object CallSite {
76
76
private [spark] object Utils extends Logging {
77
77
val random = new Random ()
78
78
79
+ private val sparkUncaughtExceptionHandler = new SparkUncaughtExceptionHandler
80
+
79
81
/**
80
82
* Define a default value for driver memory here since this value is referenced across the code
81
83
* base and nearly all files already use Utils.scala
@@ -1274,7 +1276,7 @@ private[spark] object Utils extends Logging {
1274
1276
block
1275
1277
} catch {
1276
1278
case e : ControlThrowable => throw e
1277
- case t : Throwable => SparkUncaughtExceptionHandler .uncaughtException(t)
1279
+ case t : Throwable => sparkUncaughtExceptionHandler .uncaughtException(t)
1278
1280
}
1279
1281
}
1280
1282
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ private[mesos] object MesosClusterDispatcher
97
97
with CommandLineUtils {
98
98
99
99
override def main (args : Array [String ]) {
100
- Thread .setDefaultUncaughtExceptionHandler(SparkUncaughtExceptionHandler )
100
+ Thread .setDefaultUncaughtExceptionHandler(new SparkUncaughtExceptionHandler )
101
101
Utils .initDaemon(log)
102
102
val conf = new SparkConf
103
103
val dispatcherArgs = new MesosClusterDispatcherArguments (args, conf)
You can’t perform that action at this time.
0 commit comments