Deadlock between flight recorder & VMDeath

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P3
    • 27
    • Affects Version/s: 11
    • Component/s: hotspot
    • Environment:

      This was reproduced on both Linux & macOS

    • jfr
    • generic
    • generic

      This was first noticed while testing with async-profiler https://github.com/async-profiler/async-profiler/issues/1617

      During VMDeath, the flight recorder will be shutdown, which in turn causes the `recorderthread` to complete, thus the flight recorder will no longer be able to process any new recordings

      It's possible for a user application to call `jdk.jfr.Recording#start` after the `recorderthread` is completed, which means that this new recording will be stuck infinitely waiting for the `recorderthread` to process the `MSG_START` which will never happen as the thread is already dead.

      If that happen, then that thread will forever be stuck & potentially causing the application to deadlock & fail to die

      This was reproduced on all JDK8+ including tip on both Linux & macOS

      The following small program should reliably reproduce this deadlock

      ```
      import jdk.jfr.Recording;

      public class JfrHang {

          public static void main(String[] args) {
              // Initialize JFR subsystem
              Recording r = new Recording();
              r.start();
              r.stop();

              Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                  System.out.println("Starting recording");
                  try {
                      Thread.sleep(100);
                  } catch (Exception e) {}
                  new Recording().start();
                  System.out.println("Recording started");
              }));

              System.out.println("Exiting");
          }
      }
      ```

            Assignee:
            Bara Hasheesh
            Reporter:
            Bara Hasheesh
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: