Skip to content

Commit

Permalink
fix: race condition
Browse files Browse the repository at this point in the history
* the mutex release needs to be in a `finally` block not to create a dead lock in case an exception is thrown by the cleaning method
  • Loading branch information
bruce-ricard committed May 25, 2023
1 parent 463a3c5 commit 158985a
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,16 @@ else if (map.get(USER_AUTHENTICATION_UAA_PRINCIPAL)!=null) {
protected void performExpirationCleanIfEnoughTimeHasElapsed() {
if (cleanMutex.tryAcquire()) {
//check if we should expire again
Instant now = Instant.now();
if (enoughTimeHasPassedSinceLastExpirationClean(lastClean, now)) {
//avoid concurrent deletes from the same UAA - performance improvement
lastClean = now;
actuallyPerformExpirationClean(now);
try {
Instant now = Instant.now();
if (enoughTimeHasPassedSinceLastExpirationClean(lastClean, now)) {
//avoid concurrent deletes from the same UAA - performance improvement
lastClean = now;
actuallyPerformExpirationClean(now);
}
} finally {
cleanMutex.release();
}
cleanMutex.release();
}
}

Expand Down

0 comments on commit 158985a

Please sign in to comment.