EHC ❯ Race condition in Ehcache disk overflow storage initialization
-
Bug
-
Status: Closed
-
2 Major
-
Resolution: Fixed
-
ehcache-core
-
-
cdennis
-
Reporter: tg
-
November 21, 2011
-
0
-
Watchers: 2
-
July 27, 2012
-
November 21, 2011
Description
DiskOverflowStorageFactory.getDataFile creates the temp directory if it does not yet exist:
if (!diskDir.exists() && !diskDir.mkdirs()) {
throw new CacheException("Could not create cache directory \"" + diskDir.getAbsolutePath() + "\".");
}
Unfortunately, there is a race condition in this code fragment that causes trouble if the directory is created between the diskDir.exists() and diskDir.mkdirs() calls (diskDir.mkdirs() will return false if the directory already exists).
Patch proposal:
if (!diskDir.exists() && !diskDir.mkdirs() && !diskDir.exists()) {
throw new CacheException("Could not create cache directory \"" + diskDir.getAbsolutePath() + "\".");
}
Is this a bug we should fix soon?