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

ProcessBuilderImpl does not catch exceptions thrown on background thread

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.10.3
    • Fix Version/s: None
    • Component/s: Library (Misc)
    • Labels:
      None

      Description

      If a ProcessBuilder process is internally executed on a background thread (the choice of which depends on how the process is built), exceptions thrown by a call to the underlying java.lang.ProcessBuilder.start() method are uncaught, leading to:

      • The exception hitting the thread's uncaught exception handler, and
      • Deadlocks and/or unreported errors.

      A reproduction case for 2.10.3:

      import scala.sys.process._
      import java.io.ByteArrayInputStream
      import scala.util.Try
       
      Try(("does-not-exist" #< new ByteArrayInputStream("foo".getBytes("utf-8"))).lines)
      

      The above reproduction case will deadlock waiting for initial execution of the process:

      scala> Try(("does-not-exist" #< new ByteArrayInputStream("foo".getBytes("utf-8"))).lines)
      Exception in thread "Thread-3" java.io.IOException: Cannot run program "does-not-exist": error=2, No such file or directory
              at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
              at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:68)
              at scala.sys.process.ProcessImpl$PipedProcesses.runAndExitValue(ProcessImpl.scala:131)
              at scala.sys.process.ProcessImpl$CompoundProcess$$anonfun$1.apply$mcV$sp(ProcessImpl.scala:93)
              at scala.sys.process.ProcessImpl$Spawn$$anon$1.run(ProcessImpl.scala:22)
      Caused by: java.io.IOException: error=2, No such file or directory
              at java.lang.UNIXProcess.forkAndExec(Native Method)
              at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
              at java.lang.ProcessImpl.start(ProcessImpl.java:130)
              at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
              ... 4 more
      Exception in thread "Thread-6" java.lang.RuntimeException: No exit code: process destroyed.
              at scala.sys.process.ProcessImpl$CompoundProcess.exitValue(ProcessImpl.scala:87)
              at scala.sys.process.ProcessBuilderImpl$AbstractBuilder$$anonfun$lines$1.apply$mcV$sp(ProcessBuilderImpl.scala:142)
              at scala.sys.process.ProcessImpl$Spawn$$anon$1.run(ProcessImpl.scala:22)
      // deadlocked here
      

      The bug appears to be due to IOException being thrown by java.lang.ProcessBuilder, but not being caught by its caller in scala.sys.process.ProcessBuilderImpl.Simple.run().

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              landonf Landon Fuller
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: