[SI-8406] ProcessBuilderImpl does not catch exceptions thrown on background thread Created: 13/Mar/14  Updated: 13/Mar/14

Status: Open
Project: Scala Programming Language
Component/s: Library (Misc)
Affects Version/s: Scala 2.10.3
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Landon Fuller Assignee: Unassigned
Resolution: Unresolved Votes: 1
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().


Generated at Sat Oct 20 15:28:11 CEST 2018 using JIRA 7.9.1#79001-sha1:60970b42586a2ec2760ed6cfe825b26961e62b9e.