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

Closed
scabug opened this issue Mar 13, 2014 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@scabug
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 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().

@scabug
Copy link
Author

scabug commented Mar 13, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8406?orig=1
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
Labels
Projects
None yet
Development

No branches or pull requests

4 participants