From f1eacfa0be771d65d2096f370dfbf2f36ab86b3c Mon Sep 17 00:00:00 2001 From: Bhaskarla Date: Fri, 16 Jun 2023 09:53:44 -0400 Subject: [PATCH] Fixes Racecondition: Different requests get same response #583 @mratzenb Contributed code See https://github.com/usnistgov/iheos-toolkit2/issues/583 --- .../nist/toolkit/simcommon/server/SimDb.groovy | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sim-common/src/main/java/gov/nist/toolkit/simcommon/server/SimDb.groovy b/sim-common/src/main/java/gov/nist/toolkit/simcommon/server/SimDb.groovy index 6e51da559..d93e31846 100644 --- a/sim-common/src/main/java/gov/nist/toolkit/simcommon/server/SimDb.groovy +++ b/sim-common/src/main/java/gov/nist/toolkit/simcommon/server/SimDb.groovy @@ -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'; /** @@ -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); } }