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

Process.waitForOrKill doesn't wait after killing; leading to a race condition

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.6.5, 1.7-beta-2
    • groovy-jdk
    • None
    • Ubuntu 9.04, tested with Groovy 1.6.4
      I didn't test it on Mac or WIndows.

    Description

      When 'Process.waitForOrKill' kills the process, killing the process takes some time. (One or two second) If 'Process.exitValue()' is called in this time, an IllegalThreadStateException is thrown. This does not happen always. It's a race condition.
      This "test" fails most of the time, for me:

      Process p = 'sleep 2'.execute()
      p.waitForOrKill(1000)
      p.exitValue()

      But this one always works:

      Process p = 'sleep 2'.execute()
      p.waitForOrKill(1000)
      p.waitFor()
      p.exitValue()

      I suggest 'Process.waitForOrKill' always calls 'waitFor' after killing the process.

      As a kind of "test case", you can use:

      100.times {
      Process p = 'sleep 2'.execute()
      p.waitForOrKill(1000)
      p.exitValue()
      }

      This fails always for me after one to four loops.
      But this one always completes:

      100.times {
      Process p = 'sleep 2'.execute()
      p.waitForOrKill(1000)
      p.waitFor()
      p.exitValue()
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            jan_stolzenburg Jan Stolzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: