Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8133310

OpenJDK: Process.waitFor() does not return after selenium calls on accessing /dev/urandom

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.7.0_79"
      OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1)
      OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux PCCFR 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      A process, which is executed via java.lang.Runtime.getRuntime().exec(String[] cmdarray), does not return if it reads from a system device like /dev/urandom.
      This occurs if used in combination with (in our case) the Selenium framework. If the source is compiled with OpenJDK the code does not return. If it is compiled with Oracle JDK the code is successfully executed.

      Note: Already reported at Selenium framework, from where the tip came it might be an OpenJDK bug: https://github.com/SeleniumHQ/selenium/issues/732

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the given code with OpenJDK and execute it. The program will not return.
      If the Selenium parts are commented out or the commented out command string is used instead of the used one the code succeeds.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The piece of code succeeds.
      ACTUAL -
      The execution hangs at the code execution (at proc.waitFor())

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.BufferedReader;
      import java.io.InputStreamReader;
      import java.util.Arrays;

      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;

      public class Testing {
          public static void main(String[] args) {
              WebDriver driver = null;
              driver = new FirefoxDriver();
              System.out.println("Start");
              driver.get("http://www.seleniumhq.org/");
              System.out.println("After get");
              driver.quit();
              System.out.println("Browser closed");

              // works
              // String[] cmd = { "/bin/bash", "-c", "echo 'DS%&/%s56Df%&43dsg' | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1" }; // works
              // works not
              String[] cmd = { "/bin/bash", "-c", "cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1" }; // works not
              StringBuffer buf = new StringBuffer();

              System.out.println("Call: " + Arrays.toString(cmd));

              try {
                  Process proc = Runtime.getRuntime().exec(cmd);

                  System.out.println("Now waitFor process ...");
                  proc.waitFor();
                  System.out.println("Process returned.");

                  BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));

                  String line = "";
                  while ((line = reader.readLine()) != null)
                  {
                      buf.append(line + "\n");
                  }
                  System.out.println("Buf: " + buf.toString());
              } catch (Exception e) {
                  System.out.println("ERROR");
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1.) Use Oracle JDK to compile and run the source code.
      2.) Using the example of above:
        a) comment out proc.waitFor()
        b) replace the while loop with:
      Thread.sleep(500);
      while (reader.ready())
      {
      buf.append(reader.readLine() + "\n");
      }
      proc.destroy();


            pardesha Pardeep Sharma
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: