Given the following code:
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(1))
val f = Future[Unit](throw new java.lang.InternalError())(ec)
The future f
never completes. f.value
is always None
.
There was a known bug in scala-2.10 that was fixed:
http://mandubian.com/2013/02/22/scala-future-fatal-exception
https://issues.scala-lang.org/browse/SI-7029
I am on scala-2.11.
The example from the bug report uses NotImplementedErorr, which is correctly handled by the Future and it will complete. However, if I use InternalError as in my example above, then the Future never completes. This is true whether I use the ExecutionContext.global, Executors.newSingleThreadExecutor, or Executors.newFixedThreadPool.
I can catch Throwable in the body of the Future and re-throw it with an exception wrapped around it that I know the Future will handle correctly, but that's a terrible solution.
Is this a known issue? Expected behavior? What options do I have to get sane behavior out of my Futures?