You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Sergey Gromov (JIRA)" <ji...@apache.org> on 2015/05/06 03:28:59 UTC

[jira] [Created] (GROOVY-7414) Process output not always consumed before waitFor() returns

Sergey Gromov created GROOVY-7414:
-------------------------------------

             Summary: Process output not always consumed before waitFor() returns
                 Key: GROOVY-7414
                 URL: https://issues.apache.org/jira/browse/GROOVY-7414
             Project: Groovy
          Issue Type: Bug
          Components: groovy-jdk
    Affects Versions: 2.4.3
         Environment: 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
            Reporter: Sergey Gromov
            Assignee: Guillaume Laforge


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:

{code:title=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()
        }
}
{code}

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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)