|
43 | 43 | import java.lang.management.ManagementFactory; |
44 | 44 | import java.time.Duration; |
45 | 45 | import java.time.Instant; |
| 46 | +import java.time.temporal.ChronoUnit; |
46 | 47 | import java.util.UUID; |
47 | 48 | import java.util.concurrent.CompletableFuture; |
48 | 49 | import java.util.concurrent.ScheduledExecutorService; |
@@ -179,7 +180,12 @@ protected Recording startRecording(AlertMetricType alertType, Duration duration) |
179 | 180 | try { |
180 | 181 | activeRecordingFile = createJfrFile(duration); |
181 | 182 |
|
182 | | - RecordingOptions recordingOptions = recordingOptionsBuilder.build(); |
| 183 | + // As a fallback in case recording closing logic does not succeed, set the recording |
| 184 | + // duration to the expected duration plus 60 seconds |
| 185 | + Duration requestedDuration = duration.plus(60, ChronoUnit.SECONDS); |
| 186 | + |
| 187 | + RecordingOptions recordingOptions = |
| 188 | + recordingOptionsBuilder.duration(requestedDuration.toMillis() + " ms").build(); |
183 | 189 |
|
184 | 190 | this.activeRecording = createRecording(recordingOptions, recordingConfiguration); |
185 | 191 |
|
@@ -273,15 +279,12 @@ private static void closeRecording(Recording recording, File recordingFile) { |
273 | 279 | LOGGER.error("Failed to close recording", e); |
274 | 280 | } catch (JfrStreamingException e) { |
275 | 281 | LOGGER.error("Internal JFR Error", e); |
276 | | - } finally { |
277 | | - try { |
278 | | - recording.stop(); |
279 | | - recording.close(); |
280 | | - } catch (IOException e) { |
281 | | - LOGGER.error("Failed to close recording", e); |
282 | | - } catch (JfrStreamingException e) { |
283 | | - LOGGER.error("Internal JFR Error", e); |
284 | | - } |
| 282 | + } |
| 283 | + } finally { |
| 284 | + try { |
| 285 | + recording.close(); |
| 286 | + } catch (IOException e) { |
| 287 | + LOGGER.error("Failed to close recording", e); |
285 | 288 | } |
286 | 289 | } |
287 | 290 | } |
|
0 commit comments