Skip to content

Commit

Permalink
[Java] Fix race when reusing an Aeron instance that was created in …
Browse files Browse the repository at this point in the history
…`ClusterBackup.Context.conclude` and assigned to `AeronArchive.Context`. This instance has no lock and is running in the invoker mode. The net result is sharing non-thread-safe object across the threads.
  • Loading branch information
vyazelenko committed Apr 17, 2024
1 parent 0380d7b commit fafc0cb
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,17 @@ TestMediaDriver mediaDriver()

public long recordingLogStartPosition()
{
try (RecordingLog recordingLog = new RecordingLog(clusterBackup.context().clusterDir(), false))
try (RecordingLog recordingLog = new RecordingLog(context.clusterBackupContext.clusterDir(), false))
{
final long recordingId = Objects.requireNonNull(recordingLog.findLastTerm()).recordingId;

final AeronArchive.Context ctx = clusterBackup.context().archiveContext()
.clone()
.controlResponseStreamId(ThreadLocalRandom.current().nextInt());
try (AeronArchive aeronArchive = AeronArchive.connect(ctx))
final AeronArchive.Context backupArchiveContext = context.clusterBackupContext.archiveContext();
try (AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context()
.aeronDirectoryName(backupArchiveContext.aeronDirectoryName())
.controlRequestChannel(backupArchiveContext.controlRequestChannel())
.controlRequestStreamId(backupArchiveContext.controlRequestStreamId())
.controlResponseChannel(backupArchiveContext.controlResponseChannel())
.controlResponseStreamId(ThreadLocalRandom.current().nextInt())))
{
return aeronArchive.getStartPosition(recordingId);
}
Expand Down

0 comments on commit fafc0cb

Please sign in to comment.