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

com.sun.jdi.VirtualMachine.exit() does not process shutdown sequence.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • tbd
    • 7
    • core-svc
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux martin-Latitude-E6410 2.6.38-13-generic-pae #56-Ubuntu SMP Tue Feb 14 14:32:30 UTC 2012 i686 i686 i386 GNU/Linux
      But this is irrelevant, the bug is most probably independent on the OS.

      A DESCRIPTION OF THE PROBLEM :
      When the debugger calls com.sun.jdi.VirtualMachine.exit() to stop the debuggee and finish the debugging process, the debuggee is abruptly terminated without a proper shutdown sequence.
      This can result of some staled resources not being cleaned up.
      For instance, any file that the application calls File.deleteOnExit() on, is not deleted after the application exits. Also, no shutdown hook is called.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Debug the included TestArgs class.

      Add breakpoint to the for() cycle and when debugger suspends there, call com.sun.jdi.VirtualMachine.exit(0)
      The test lock files are not deleted.
      If the application is terminated by System.exit(0), the lock files are correctly deleted.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It's expected that com.sun.jdi.VirtualMachine.exit(0) behaves like detaching the debugger and then calling System.exit(0) in the debuggee.

      If it's not possible to change the current behavior, it would be really desired to have a method that would act like that, to be able to cleanly shutdown the debuggee.
      ACTUAL -
      The debuggee exits without any cleanup. This cause problems with staled resources.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;

      /**
       *
       * @author tim.milo
       */
      public class TestArgs {
          
          private static final String LOCK_FILE = "/tmp/testLock";
          private static final String LOCK_FILE_DE = "/tmp/testLockDeleteOnExit";

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) throws IOException {
              Runtime.getRuntime().addShutdownHook(new ShutdownThread());
              BufferedWriter w = new BufferedWriter(new FileWriter(LOCK_FILE));
              w.write("Test "+System.currentTimeMillis());
              w.close();
              
              w = new BufferedWriter(new FileWriter(LOCK_FILE_DE));
              w.write("Test "+System.currentTimeMillis());
              w.close();
              new File(LOCK_FILE_DE).deleteOnExit();
              
              for(int i = 0; i < args.length; i++){
                  System.out.println("args[" + i + "] = " + args[i]);
              }
          }

          private static class ShutdownThread extends Thread {

              public ShutdownThread() {
              }

              @Override
              public void run() {
                  System.err.println("Cleanup execution...");
                  new File(LOCK_FILE).delete();
              }
              
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      I did not find a workaround.
      One could be to invoke System.exit(0) method via debugger, but method invocation is possible only if the debuggee is stopped on an event. This might not be the case, in general.

            dsamersoff Dmitriy Samersoff
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: