ADDITIONAL SYSTEM INFORMATION :
Windows 10, JDK 13
A DESCRIPTION OF THE PROBLEM :
When starting processes using java.lang.ProcessBuilder / java.lang.Process, the Windows handle count increases continuously. This leads to the system becoming unresponsive after reaching several hundred thousand handles.
Java 8 and Java 9 are not affected, the regression seems to occur since Java 10.
REGRESSION : Last worked in version 8u241
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test program below. Observe the handle count in den Windows Task Manager by enabling the handle column in the details tab.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Windows handle count stays stable.
ACTUAL -
Windows handle count increases continuously.
---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class HandleLeak {
public static void main(String[] args) {
while( true ) {
try {
Process testProcess = new ProcessBuilder("cmd", "/c", "dir").start();
Thread outputConsumer = new Thread(() -> consumeStream( testProcess.getInputStream() ) );
outputConsumer.setDaemon( true );
outputConsumer.start();
Thread errorConsumer = new Thread(() -> consumeStream( testProcess.getErrorStream() ) );
errorConsumer.setDaemon( true );
errorConsumer.start();
testProcess.waitFor();
System.gc();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
private static void consumeStream( InputStream inputStream ) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(inputStream));
while( reader.readLine() != null ) {
;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if( reader != null ) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
---------- END SOURCE ----------
FREQUENCY : always