Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7414

Process output not always consumed before waitFor() returns

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.3
    • None
    • groovy-jdk
    • None
    • Linux junk 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-2 (2015-04-13) x86_64 GNU/Linux running in a VirtualBox VM

    Description

      Sometimes the Process.consumeProcessOutput(Appendable, Appendable) and Process.waitFor() combination does not work as expected. More specifically, sometimes waitFor() returns before all input is actually written into Appendable.

      The following script reproduces the problem:

      bug.gy
      100.times {
              def out = new StringBuilder()
              def err = new StringBuilder()
              def p = 'echo stuff'.execute()
              p.consumeProcessOutput(out, err)
              p.waitFor()
              def s = out.toString()
              if (s != 'stuff\n') {
                      println 'Bug!'
                      println 'OUT: ' + s.inspect()
              }
      }
      

      The ability to reproduce this issue seems to depend on the system performance. E.g. I can easily reproduce it in my virtual Linux box. The above script fails 2 or 3 times on every launch. OTOH it's quite problematic to reproduce on my host Windows machine even though I increased the number of tries to 1000. Nevertheless I have reproduced it on Windows, too, a couple of times.

      I think this is major because I'm not aware of any viable workaround. The only thing that works is to sleep a bit after waitFor() which is often unacceptable, and it's impossible to guess for how long to sleep.

      Note that Process.consumeProcessOutput(OutputStream, OutputStream) exhibits the same broken behavior.

      Also note that Process.waitForProcessOutput(arg, arg) methods work flawlessly.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sgromov Sergey Gromov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: