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

Document the possible race condition when using consumeProcessOutput()

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.2, 2.4.0-beta-1, 2.3.4
    • Fix Version/s: 2.3.7, 2.4.0-beta-3
    • Component/s: None
    • Labels:
      None

      Description

      There seems to be a bug in consumeProcessOutput that leads to the effect that the output captured in a StringBuilder is not available at the time it is accessed even after a waitFor(). The following code shows the behavior. (Tested on the listed versions.)

      int cnt0 = 0;
      int cnt1 = 0;
      for (int i=0;i<10000;i++) {
      StringBuilder sb = new StringBuilder();
      def proc = "whoami".execute();
      proc.consumeProcessOutput(sb,sb);
      proc.waitFor();
      def a = sb.readLines();
      def b = sb.readLines();
      def c = sb.readLines();
           if( a.size() != b.size()) {
               print(".");
               cnt0++;
           }
           if( b.size() != c.size()) {
               print(",");
               cnt1++;
           }
      }
      println ""
      println cnt0
      println cnt1
      

      Example output:

      ,..,.,.
      4
      3
      

      Adding a short sleep after waitFor "fixes" the issue. I expect the threads used to consume the output are not joined in waitFor but did not look deeper into the issue. If you need additional information, feel free to ask!

      Best regards,
      Manuel

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              mprinz Manuel Prinz
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: