From 3cf194e476dab4218dd637a9d56904e1e379ebbf Mon Sep 17 00:00:00 2001 From: Katherine Yen Date: Wed, 17 Sep 2025 12:02:39 -0400 Subject: [PATCH] Catch `IllegalStateException` when closing `RecordingStream` --- .../textsecuregcm/util/VirtualThreadPinEventMonitor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/VirtualThreadPinEventMonitor.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/VirtualThreadPinEventMonitor.java index 5edcd6cdb..c2ccfb6e5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/util/VirtualThreadPinEventMonitor.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/VirtualThreadPinEventMonitor.java @@ -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(); }