Skip to content

Commit 894aee1

Browse files
dragosretronym
authored andcommitted
Start the PC thread only after initialization of required symbols.
If the class path is incomplete, the presentation compiler might crash during construction. If the PC thread was already started, it will never get the chance to shutdown, and the thread leaks. In the IDE, where the PC is started when needed, this can lead to a very quick depletion of JVM threads. See Scala IDE #1002016.
1 parent ea36cad commit 894aee1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/interactive/scala/tools/nsc/interactive/Global.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
534534
threadId += 1
535535
compileRunner = new PresentationCompilerThread(this, projectName)
536536
compileRunner.setDaemon(true)
537-
compileRunner.start()
538537
compileRunner
539538
}
540539

@@ -1252,11 +1251,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
12521251

12531252
forceSymbolsUsedByParser()
12541253

1254+
/** Start the compiler background thread and turn on thread confinement checks */
1255+
private def finishInitialization(): Unit = {
1256+
// this flag turns on `assertCorrectThread checks`
1257+
initializing = false
1258+
1259+
// Only start the thread if initialization was successful. A crash while forcing symbols (for example
1260+
// if the Scala library is not on the classpath) can leave running threads behind. See Scala IDE #1002016
1261+
compileRunner.start()
1262+
}
1263+
12551264
/** The compiler has been initialized. Constructors are evaluated in textual order,
1256-
* so this is set to true only after all super constructors and the primary constructor
1265+
* if we reached here, all super constructors and the primary constructor
12571266
* have been executed.
12581267
*/
1259-
initializing = false
1268+
finishInitialization()
12601269
}
12611270

12621271
object CancelException extends Exception

0 commit comments

Comments
 (0)