Skip to content
Snippets Groups Projects
Commit 92ca910e authored by Timothy Hunter's avatar Timothy Hunter Committed by Matei Zaharia
Browse files

[SPARK-2762] SparkILoop leaks memory in multi-repl configurations

This pull request is a small refactor so that a partial function (hence a closure) is not created. Instead, a regular function is used. The behavior of the code is not changed.

Author: Timothy Hunter <timhunter@databricks.com>

Closes #1674 from thunterdb/closure_issue and squashes the following commits:

e1e664d [Timothy Hunter] simplify closure
parent 669e3f05
No related branches found
No related tags found
No related merge requests found
......@@ -557,29 +557,27 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter,
if (isReplPower) powerCommands else Nil
)*/
val replayQuestionMessage =
private val replayQuestionMessage =
"""|That entry seems to have slain the compiler. Shall I replay
|your session? I can re-run each line except the last one.
|[y/n]
""".trim.stripMargin
private val crashRecovery: PartialFunction[Throwable, Boolean] = {
case ex: Throwable =>
echo(intp.global.throwableAsString(ex))
ex match {
case _: NoSuchMethodError | _: NoClassDefFoundError =>
echo("\nUnrecoverable error.")
throw ex
case _ =>
def fn(): Boolean =
try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
catch { case _: RuntimeException => false }
if (fn()) replay()
else echo("\nAbandoning crashed session.")
}
true
private def crashRecovery(ex: Throwable): Boolean = {
echo(ex.toString)
ex match {
case _: NoSuchMethodError | _: NoClassDefFoundError =>
echo("\nUnrecoverable error.")
throw ex
case _ =>
def fn(): Boolean =
try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
catch { case _: RuntimeException => false }
if (fn()) replay()
else echo("\nAbandoning crashed session.")
}
true
}
/** The main read-eval-print loop for the repl. It calls
......@@ -605,7 +603,10 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter,
}
}
def innerLoop() {
if ( try processLine(readOneLine()) catch crashRecovery )
val shouldContinue = try {
processLine(readOneLine())
} catch {case t: Throwable => crashRecovery(t)}
if (shouldContinue)
innerLoop()
}
innerLoop()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment