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, ...@@ -557,29 +557,27 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter,
if (isReplPower) powerCommands else Nil if (isReplPower) powerCommands else Nil
)*/ )*/
val replayQuestionMessage = private val replayQuestionMessage =
"""|That entry seems to have slain the compiler. Shall I replay """|That entry seems to have slain the compiler. Shall I replay
|your session? I can re-run each line except the last one. |your session? I can re-run each line except the last one.
|[y/n] |[y/n]
""".trim.stripMargin """.trim.stripMargin
private val crashRecovery: PartialFunction[Throwable, Boolean] = { private def crashRecovery(ex: Throwable): Boolean = {
case ex: Throwable => echo(ex.toString)
echo(intp.global.throwableAsString(ex)) ex match {
case _: NoSuchMethodError | _: NoClassDefFoundError =>
ex match { echo("\nUnrecoverable error.")
case _: NoSuchMethodError | _: NoClassDefFoundError => throw ex
echo("\nUnrecoverable error.") case _ =>
throw ex def fn(): Boolean =
case _ => try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
def fn(): Boolean = catch { case _: RuntimeException => false }
try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
catch { case _: RuntimeException => false } if (fn()) replay()
else echo("\nAbandoning crashed session.")
if (fn()) replay() }
else echo("\nAbandoning crashed session.") true
}
true
} }
/** The main read-eval-print loop for the repl. It calls /** The main read-eval-print loop for the repl. It calls
...@@ -605,7 +603,10 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter, ...@@ -605,7 +603,10 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter,
} }
} }
def innerLoop() { def innerLoop() {
if ( try processLine(readOneLine()) catch crashRecovery ) val shouldContinue = try {
processLine(readOneLine())
} catch {case t: Throwable => crashRecovery(t)}
if (shouldContinue)
innerLoop() innerLoop()
} }
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