java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
FULL OS VERSION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Using the following JVM options:
-verbose:gc -Xloggc:C:/test/log/gc.log
A DESCRIPTION OF THE PROBLEM :
We use JVM options -verbose:gc and -Xloggc:<path> to log garbage collection events to a file. As expected, the Java process holds a lock to the GC log file.
However, when we spawn a child process from the main process, the child process also holds a lock to the GC log file. This is an issue because when our main Java process exits, we can't delete the GC log file until the child process also exits.
File handles from the main Java process should not be leaking to child processes.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1- Launch a Java application with JVM options: -verbose:gc -Xloggc:C:/test/log/gc.log
2- Spawn a child process from the Java application
3- Using a tool such as Process Explorer, watch how the spawned child process holds a lock on the GC log file.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected behavior: The child process should not hold a lock on the GC log file.
Actual behavior: The child process holds a lock on the GC log file.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
1- GcLogTest.java
public class GcLogTest {
// VM options:
// -verbose:gc -Xloggc:C:/test/log/gc.log
public static void main(String[] args) throws InterruptedException, IOException {
// Start sub-process, but don't wait for it to exit
List<String> command = Arrays.asList("C:\\test\\log\\wait_test.bat", "180");
ProcessBuilder pb = new ProcessBuilder(command);
Process childProcess = pb.start();
// Wait 30 seconds
Thread.sleep(30 * 1000L);
// Exit without killing process
}
}
2- wait_test.bat
@echo off
REM %1 Time to wait in seconds
ping -n %1 localhost >nul
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Disable GC logging to file.
- duplicates
-
JDK-8176809 UL Log file handles leaked to child processes
-
- Closed
-
- is cloned by
-
JDK-8176809 UL Log file handles leaked to child processes
-
- Closed
-
- relates to
-
JDK-8202720 (process) Clarify file handler behaviour
-
- Open
-
-
JDK-8202740 runtime/8176717/TestInheritFD.java fails with java.lang.RuntimeException: could not match: VM RESULT => RETAINS FD
-
- Resolved
-
-
JDK-8222500 runtime/8176717/TestInheritFD.java failed with java.nio.file.NoSuchFileException: /tmp/communication7071713601211876892.txt
-
- Resolved
-
-
JDK-8347001 runtime/8176717/TestInheritFD.java failed on Ubuntu 24.10 with java.util.concurrent.CompletionException
-
- Closed
-