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

GC log file handle leaked to child processes

XMLWordPrintable

    • gc
    • b13
    • generic
    • windows

      FULL PRODUCT VERSION :
      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.

            lkorinth Leo Korinth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: