Catch IllegalStateException when closing RecordingStream

This commit is contained in:
Katherine Yen authored and ravi-signal committed 2025-09-18 13:53:31 -05:00
1 parent bad2602491
commit 3cf194e476
1 file changed
+8 -1
@@ -68,7 +68,14 @@ public class VirtualThreadPinEventMonitor implements Managed {
@Override
public void stop() throws InterruptedException {
// flushes events and waits for callbacks to finish
recordingStream.stop();
try {
recordingStream.stop();
} catch (final IllegalStateException _) {
// The JFR recorder registers its own shutdown hook with the JVM.
// Since shutdown hook execution order is not guaranteed but JFR's hook usually runs early,
// this recording may already be stopped before our managed resource cleanup runs.
logger.info("RecordingStream already stopped");
}
// immediately frees all resources
recordingStream.close();
}