Skip to content

Apache Lucene open-source search software

LUCENE-5626: Fix bug in SimpleFSLockFactory's obtain() that sometimes throwed IOException (ERROR_ACESS_DENIED) on Windows if the lock file was created concurrently

Uwe Schindleree060ebca160
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9287fe3d01a..42a2c4fa59e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -99,6 +99,11 @@ Bug fixes
* LUCENE-5600: HttpClientBase did not properly consume a connection if a server
error occurred. (Christoph Kaser via Shai Erera)
+* LUCENE-5626: Fix bug in SimpleFSLockFactory's obtain() that sometimes throwed
+ IOException (ERROR_ACESS_DENIED) on Windows if the lock file was created
+ concurrently. This error is now handled the same way like in NativeFSLockFactory
+ by returning false. (Uwe Schindler, Robert Muir, Dawid Weiss)
+
======================= Lucene 4.8.0 =======================
System Requirements
diff --git a/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java b/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
index 05b2ef3ccbe..6bae591a94b 100644
--- a/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
@@ -132,7 +132,17 @@ class SimpleFSLock extends Lock {
throw new IOException("Found regular file where directory expected: " +
lockDir.getAbsolutePath());
}
- return lockFile.createNewFile();
+
+ try {
+ return lockFile.createNewFile();
+ } catch (IOException ioe) {
+ // On Windows, on concurrent createNewFile, the 2nd process gets "access denied".
+ // In that case, the lock was not aquired successfully, so return false.
+ // We record the failure reason here; the obtain with timeout (usually the
+ // one calling us) will use this as "root cause" if it fails to get the lock.
+ failureReason = ioe;
+ return false;
+ }
}
@Override