Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcessBuilderImpl does not catch exceptions thrown on background thread #8406

scabug opened this issue Mar 13, 2014 · 1 comment


Copy link

scabug commented Mar 13, 2014

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 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" Cannot run program "does-not-exist": error=2, No such file or directory
        at java.lang.ProcessBuilder.start(
        at scala.sys.process.ProcessBuilderImpl$
        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$
Caused by: error=2, No such file or directory
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(
        at java.lang.ProcessImpl.start(
        at java.lang.ProcessBuilder.start(
        ... 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$
// deadlocked here

The bug appears to be due to IOException being thrown by java.lang.ProcessBuilder, but not being caught by its caller in

Copy link

scabug commented Mar 13, 2014

Imported From:
Reporter: Landon Fuller (landonf)
Affected Versions: 2.10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants