JDK-4637504 : (process) REGRESSION: java.lang.Process does not clean up file resources
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2002-02-13
  • Updated: 2002-03-29
  • Resolved: 2002-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 hopperFixed
Related Reports
Relates :  
Relates :  
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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper FIXED IN: hopper INTEGRATED IN: hopper VERIFIED IN: hopper
14-06-2004

EVALUATION We need to close input output and error stream in Process.destroy() ###@###.### 2002-02-22
22-02-2002