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

(process) REGRESSION: java.lang.Process does not clean up file resources

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.4.1
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      sparc
    • OS:
      solaris_8
    • Verification:
      Verified

      Description



      Name: rmT116609 Date: 02/13/2002


      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      SunOS mars 5.8 Generic_108528-09 sun4u sparc SUNW,Ultra-250

      A DESCRIPTION OF THE PROBLEM :
      If you keep on calling Runtime.exec(SomeUnixProgram). After about 337 time, java stops and complain that two many files are open.

      REGRESSION. Last worked in version 1.1.8, 1.2.2

      The problem is reproducible on Solaris2.8 using JDK1.3.0, 1.3.1_02, 1.4.0-rc.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. javac -d $CLASSPATH Test.java
      2. /usr/java1.1/bin/java tmp.Test that works fine
      3. /usr/j2se/bin/java tmp.Test that stops after 337 exec()


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The program should runs forever, like in JDK 1.1.8, 1.2.2.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      ...
      333
      334
      335
      336
      337
      Exception in thread "main" java.io.IOException: Too many open files
              at java.lang.UNIXProcess.forkAndExec(Native Method)
              at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
              at java.lang.Runtime.execInternal(Native Method)
              at java.lang.Runtime.exec(Runtime.java:551)
              at java.lang.Runtime.exec(Runtime.java:418)
              at java.lang.Runtime.exec(Runtime.java:361)
              at java.lang.Runtime.exec(Runtime.java:325)
              at tmp.Test.main(Test.java:8)
      mars%


      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package tmp;
      import java.io.*;
      class Test {
          public static void main(String[] args) throws Exception {
              Runtime runtime = Runtime.getRuntime();
              byte[] buffer = new byte[4096];
              for (int i = 0;; i++) {
                  Process process = runtime.exec("echo " + i);
                  process.waitFor();
                  InputStream input = process.getErrorStream();
                  int n = input.read(buffer);
                  if (n > 0) System.out.write(buffer, 0, n);
                  input = process.getInputStream();
                  n = input.read(buffer);
                  if (n > 0) System.out.write(buffer, 0, n);
                  System.out.flush();
                  process.destroy();
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      add System.gc(); after process.destroy(); bypass this bug. But gc() is too expensive.
      (Review ID: 139633)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kkladkosunw Konstantin Kladko (Inactive)
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: