Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-7029

Fork join execution context loses fatal exceptions

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: Scala 2.10.1
    • Component/s: Concurrent Library
    • Labels:
      None

      Description

      The fork join execution context loses fatal exceptions. It should allow them to be handled by the threads uncaught exception handler, so that they can be logged. But it doesn't, they get lost, not reported anywhere. Here is an example in the repl:

      scala> import scala.concurrent._
      import scala.concurrent._
       
      scala> val ec = scala.concurrent.ExecutionContext.global
      ec: scala.concurrent.ExecutionContextExecutor = scala.concurrent.impl.ExecutionContextImpl@4a640180
       
      scala> val f = Future[Unit](throw new NotImplementedError())(ec)
      f: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@3ec9e1f9
      

      Nothing happens. What I expected is for my NotImplementedError to be at least handled by the uncaught exception handler, and logged. Now, I know the uncaught exception handler is there and working:

      scala> val f = Future[Unit](Thread.currentThread.getUncaughtExceptionHandler.uncaughtException(Thread.currentThread, new NotImplementedError()))(ec)
      f: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@4aac53a8
      Exception in thread "ForkJoinPool-1-worker-1" scala.NotImplementedError: an implementation is missing
      	at $line53.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply$mcV$sp(<console>:11)
      	at $line53.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:11)
      	at $line53.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:11)
      	at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
      	at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
      	at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417)
      	at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
      	at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
      	at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
      	at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
      

      And if I use a different execution context, such as a Java executor, it works as expected:

      scala> val es = java.util.concurrent.Executors.newSingleThreadExecutor
      es: java.util.concurrent.ExecutorService = java.util.concurrent.Executors$FinalizableDelegatedExecutorService@10cd508f
       
      scala> val ec = ExecutionContext.fromExecutorService(es)
      ec: scala.concurrent.ExecutionContextExecutorService = scala.concurrent.impl.ExecutionContextImpl$$anon$1@11e9c5a7
       
      scala> val f = Future[Unit](throw new NotImplementedError())(ec)
      f: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@7309eabd
      Exception in thread "pool-1-thread-1" scala.NotImplementedError: an implementation is missing
       
       	at $line69.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:12)
      	at $line69.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:12)
      	at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
      	at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      	at java.lang.Thread.run(Thread.java:722)
      

        Attachments

          Activity

            People

            • Assignee:
              phaller Philipp Haller
              Reporter:
              jroper James Roper
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: