Skip to content

Commit 7d1b769

Browse files
committed
SPARK-1097: Do not introduce deadlock while fixing concurrency bug
We recently added this lock on 'conf' in order to prevent concurrent creation. However, it turns out that this can introduce a deadlock because Hadoop also synchronizes on the Configuration objects when creating new Configurations (and they do so via a static REGISTRY which contains all created Configurations). This fix forces all Spark initialization of Configuration objects to occur serially by using a static lock that we control, and thus also prevents introducing the deadlock.
1 parent bf04a39 commit 7d1b769

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/main/scala/org/apache/spark/rdd/HadoopRDD.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class HadoopRDD[K, V](
140140
// Create a JobConf that will be cached and used across this RDD's getJobConf() calls in the
141141
// local process. The local cache is accessed through HadoopRDD.putCachedMetadata().
142142
// The caching helps minimize GC, since a JobConf can contain ~10KB of temporary objects.
143-
// synchronize to prevent ConcurrentModificationException (Spark-1097, Hadoop-10456)
144-
conf.synchronized {
143+
// Synchronize to prevent ConcurrentModificationException (Spark-1097, Hadoop-10456).
144+
HadoopRDD.CONFIGURATION_INSTANTIATION_LOCK.synchronized {
145145
val newJobConf = new JobConf(conf)
146146
initLocalJobConfFuncOpt.map(f => f(newJobConf))
147147
HadoopRDD.putCachedMetadata(jobConfCacheKey, newJobConf)
@@ -246,6 +246,9 @@ class HadoopRDD[K, V](
246246
}
247247

248248
private[spark] object HadoopRDD {
249+
/** Constructing Configuration objects is not threadsafe, use this lock to serialize. */
250+
val CONFIGURATION_INSTANTIATION_LOCK = new Object()
251+
249252
/**
250253
* The three methods below are helpers for accessing the local map, a property of the SparkEnv of
251254
* the local process.

0 commit comments

Comments
 (0)