From 217257879fe7c98673caf14b980790498887581e Mon Sep 17 00:00:00 2001 From: Dale Date: Fri, 26 Dec 2014 20:33:05 +1100 Subject: [PATCH 1/2] [SPARK-4787] Stop context properly if an exception occurs during DAGScheduler initialization. --- core/src/main/scala/org/apache/spark/SparkContext.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala b/core/src/main/scala/org/apache/spark/SparkContext.scala index 57bc3d4e4ae36..2778975976b26 100644 --- a/core/src/main/scala/org/apache/spark/SparkContext.scala +++ b/core/src/main/scala/org/apache/spark/SparkContext.scala @@ -329,8 +329,11 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli try { dagScheduler = new DAGScheduler(this) } catch { - case e: Exception => throw - new SparkException("DAGScheduler cannot be initialized due to %s".format(e.getMessage)) + case e: Exception => { + stop() + throw + new SparkException("DAGScheduler cannot be initialized due to %s".format(e.getMessage)) + } } // start TaskScheduler after taskScheduler sets DAGScheduler reference in DAGScheduler's From 5661e01c2b0aaf900b50fb2444db714f73021aa4 Mon Sep 17 00:00:00 2001 From: Dale Date: Tue, 30 Dec 2014 11:06:48 +1100 Subject: [PATCH 2/2] [SPARK-4787] Ensure that call to stop() doesn't lose the exception by using a finally block. --- core/src/main/scala/org/apache/spark/SparkContext.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala b/core/src/main/scala/org/apache/spark/SparkContext.scala index 2778975976b26..42a726ae40045 100644 --- a/core/src/main/scala/org/apache/spark/SparkContext.scala +++ b/core/src/main/scala/org/apache/spark/SparkContext.scala @@ -330,9 +330,11 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli dagScheduler = new DAGScheduler(this) } catch { case e: Exception => { - stop() - throw - new SparkException("DAGScheduler cannot be initialized due to %s".format(e.getMessage)) + try { + stop() + } finally { + throw new SparkException("Error while constructing DAGScheduler", e) + } } }