Scala Programming Language
  1. Scala Programming Language
  2. SI-6488

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0-M7
    • Fix Version/s: Scala 2.11.0-M3
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        Josh Graham added a comment -

        With PR https://github.com/scala/scala/pull/1522 accepted, are you going to backport to 2.9?

        Show
        Josh Graham added a comment - With PR https://github.com/scala/scala/pull/1522 accepted, are you going to backport to 2.9?
        Hide
        Jed Wesley-Smith added a comment -

        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.

        Show
        Jed Wesley-Smith added a comment - 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.
        Hide
        Adriaan Moors added a comment -

        Refined to use Thread.interrupt in https://github.com/scala/scala/pull/2538

        Show
        Adriaan Moors added a comment - Refined to use Thread.interrupt in https://github.com/scala/scala/pull/2538
        Hide
        Adriaan Moors added a comment -

        Unassigning and rescheduling to M6 as previous deadline was missed.

        Show
        Adriaan Moors added a comment - Unassigning and rescheduling to M6 as previous deadline was missed.
        Hide
        Jason Zaugg added a comment -

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

        Show
        Jason Zaugg added a comment - Looks like we forgot to close this ticket. Andrew: if I'm missing any residual problems, could you please open a followup ticket?

          People

          • Assignee:
            A. P. Marki
            Reporter:
            Jed Wesley-Smith
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development