Skip to content

Commit

Permalink
Fixes Racecondition: Different requests get same response #583
Browse files Browse the repository at this point in the history
@mratzenb Contributed code
See #583
  • Loading branch information
Bhaskarla authored and Bhaskarla committed Jun 16, 2023
1 parent b11c62d commit f1eacfa
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class SimDb {
static String luceneIndexDirectoryName = 'simindex'
private TestSession testSession = null;
static String simTypeFilename = 'sim_type.txt'
private static final Object fileLock = new Object();

static final String MARKER = 'MARKER';
/**
Expand Down Expand Up @@ -111,9 +112,17 @@ public class SimDb {
if (openToLastTransaction) {
openMostRecentEvent(actor, transaction)
} else {
eventDate = new Date();
File eventDir = mkEventDir(eventDate);
eventDir.mkdirs();
/**
* Fixes race condition
* @mratzenb Contributed code
* See https://github.com/usnistgov/iheos-toolkit2/issues/583
*/
File eventDir;
synchronized (fileLock) {
eventDate = new Date();
eventDir = mkEventDir(eventDate);
eventDir.mkdirs();
}
Serialize.out(new File(eventDir, "date.ser"), eventDate);
}
}
Expand Down

0 comments on commit f1eacfa

Please sign in to comment.