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

scala.sys.process.ProcessImpl.SimpleProcess.destroy() doesn't clean up the output threads nicely #6488

Closed
scabug opened this issue Oct 9, 2012 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Oct 9, 2012

SimpleProcess doesn't cleanup its output threads when destroying the underlying Java thread:

sys.process.Process("sleep 10").run(sys.process.ProcessLogger { 
  (s: String) => println(s)
}).destroy

leads to

[error] (Thread-72) java.io.IOException: Stream closed
s: Unit = ()
[error] (Thread-73) java.io.IOException: Bad file descriptor

scala> java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
	at java.io.InputStreamReader.read(InputStreamReader.java:167)
	at java.io.BufferedReader.fill(BufferedReader.java:136)
	at java.io.BufferedReader.readLine(BufferedReader.java:299)
	at java.io.BufferedReader.readLine(BufferedReader.java:362)
	at scala.sys.process.BasicIO$$anonfun$processFully$1$$anonfun$apply$6.apply(BasicIO.scala:164)
	at scala.sys.process.BasicIO$$anonfun$processFully$1$$anonfun$apply$6.apply(BasicIO.scala:164)
	at scala.sys.process.BasicIO$.readFully$1(BasicIO.scala:173)
	at scala.sys.process.BasicIO$.processLinesFully(BasicIO.scala:179)
	at scala.sys.process.BasicIO$$anonfun$processFully$1.apply(BasicIO.scala:164)
	at scala.sys.process.BasicIO$$anonfun$processFully$1.apply(BasicIO.scala:162)
	at scala.sys.process.ProcessBuilderImpl$Simple$$anonfun$3.apply$mcV$sp(ProcessBuilderImpl.scala:73)
	at scala.sys.process.ProcessImpl$Spawn$$anon$1.run(ProcessImpl.scala:22)
java.io.IOException: Bad file descriptor
	at java.io.FileInputStream.readBytes(Native Method)
	at java.io.FileInputStream.read(FileInputStream.java:220)
	at java.lang.UNIXProcess$DeferredCloseInputStream.read(UNIXProcess.java:227)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
	at java.io.InputStreamReader.read(InputStreamReader.java:167)
	at java.io.BufferedReader.fill(BufferedReader.java:136)
	at java.io.BufferedReader.readLine(BufferedReader.java:299)
	at java.io.BufferedReader.readLine(BufferedReader.java:362)
	at scala.sys.process.BasicIO$$anonfun$processFully$1$$anonfun$apply$6.apply(BasicIO.scala:164)
	at scala.sys.process.BasicIO$$anonfun$processFully$1$$anonfun$apply$6.apply(BasicIO.scala:164)
	at scala.sys.process.BasicIO$.readFully$1(BasicIO.scala:173)
	at scala.sys.process.BasicIO$.processLinesFully(BasicIO.scala:179)
	at scala.sys.process.BasicIO$$anonfun$processFully$1.apply(BasicIO.scala:164)
	at scala.sys.process.BasicIO$$anonfun$processFully$1.apply(BasicIO.scala:162)
	at scala.sys.process.ProcessBuilderImpl$Simple$$anonfun$4.apply$mcV$sp(ProcessBuilderImpl.scala:76)
	at scala.sys.process.ProcessImpl$Spawn$$anon$1.run(ProcessImpl.scala:22)

In our code which has long running processes, we are seeing java.io.IOException: Bad file descriptor being thrown when we destroy the process. The above only seems to get that (and the Stream Closed) if we destroy as soon as we create.

@scabug
Copy link
Author

@scabug scabug commented Oct 9, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6488?orig=1
Reporter: Jed Wesley-Smith (jedws)
Affected Versions: 2.9.2, 2.10.0-M7

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 1, 2012

Josh Graham (delitescere) said:
With PR scala/scala#1522 accepted, are you going to backport to 2.9?

Loading

@scabug
Copy link
Author

@scabug scabug commented Feb 15, 2013

Jed Wesley-Smith (jedws) said:
AFAICT this should be closed fixed against 2.10 – see above PR and here's link showing it is definitely in 2.10.1 branch: https://github.com/scala/scala/blob/2.10.1/src/library/scala/sys/process/ProcessImpl.scala

Assigning to Josh Suereth for follow-up.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 17, 2013

@adriaanm said:
Refined to use Thread.interrupt in scala/scala#2538

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 21, 2013

@retronym said:
Looks like we forgot to close this ticket. Andrew: if I'm missing any residual problems, could you please open a followup ticket?

Loading

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

Successfully merging a pull request may close this issue.

None yet
2 participants