Skip to content

Commit 58dba70

Browse files
committed
SPARK-2645: Fix for SparkContext stop behavior
1 parent 380c5b0 commit 58dba70

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

core/src/main/scala/org/apache/spark/SparkEnv.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SparkEnv (
9393

9494
private[spark] def stop() {
9595

96-
if(!isStopped) {
96+
if (!isStopped) {
9797
isStopped = true
9898
try {
9999
pythonWorkers.foreach { case (key, worker) => worker.stop()}

core/src/test/scala/org/apache/spark/SparkContextSuite.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.apache.spark.util.Utils
3030

3131
import scala.concurrent.Await
3232
import scala.concurrent.duration.Duration
33+
import scala.util.control.NonFatal
3334

3435
class SparkContextSuite extends SparkFunSuite with LocalSparkContext {
3536

@@ -272,4 +273,24 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext {
272273
sc.stop()
273274
}
274275
}
276+
277+
test("calling multiple sc.stop() must not throw uncaught exception(50) from sparkenv") {
278+
var threwNoOrOnlyExceptedException = true
279+
try {
280+
sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local"))
281+
val cnt = sc.parallelize(1 to 4).count()
282+
sc.cancelAllJobs()
283+
sc.stop()
284+
// call stop second time
285+
sc.stop()
286+
} catch {
287+
case e: ServerStateException =>
288+
// assert(!e.getMessage.contains("Server is already stopped"))
289+
threwNoOrOnlyExceptedException = false
290+
case NonFatal(e) =>
291+
threwNoOrOnlyExceptedException = true
292+
} finally {
293+
assert(threwNoOrOnlyExceptedException == true)
294+
}
295+
}
275296
}

0 commit comments

Comments
 (0)