Skip to content

Commit

Permalink
correct snapshot validation before creating recording record, fix con…
Browse files Browse the repository at this point in the history
…current modification exception
  • Loading branch information
andrewazores committed Nov 21, 2023
1 parent 4165077 commit 571709f
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -218,6 +217,14 @@ public ActiveRecording createSnapshot(Target target, JFRConnection connection)

desc = updatedDescriptor.get();

try (InputStream snapshot = remoteRecordingStreamFactory.open(connection, target, desc)) {
if (!snapshotIsReadable(target, snapshot)) {
connection.getService().close(desc);
throw new SnapshotCreationException(
"Snapshot was not readable - are there any source recordings?");
}
}

ActiveRecording recording =
ActiveRecording.from(
target,
Expand All @@ -233,15 +240,6 @@ public ActiveRecording createSnapshot(Target target, JFRConnection connection)
target.activeRecordings.add(recording);
target.persist();

try (InputStream snapshot = getActiveInputStream(target.id, desc.getId())) {
if (!snapshotIsReadable(target, snapshot)) {
String snapshotName = desc.getName();
this.deleteRecording(target, r -> Objects.equals(r.name, snapshotName));
throw new SnapshotCreationException(
"Snapshot was not readable - are there any source recordings?");
}
}

bus.publish(
MessagingServer.class.getName(),
new Notification(
Expand All @@ -250,10 +248,6 @@ public ActiveRecording createSnapshot(Target target, JFRConnection connection)
return recording;
}

public void deleteRecording(Target target, Predicate<ActiveRecording> predicate) {
target.activeRecordings.stream().filter(predicate).forEach(ActiveRecording::delete);
}

private boolean snapshotIsReadable(Target target, InputStream snapshot) throws IOException {
if (!connectionManager.markConnectionInUse(target)) {
throw new IOException(
Expand Down

0 comments on commit 571709f

Please sign in to comment.