Merge pull request #11412 from s1monw/close_lock

Close lock even if we fail to obtain
This commit is contained in:
Simon Willnauer 2015-05-29 13:37:54 +02:00
commit a7779d8e1d
1 changed files with 10 additions and 2 deletions

View File

@ -189,9 +189,17 @@ public class Lucene {
@SuppressForbidden(reason = "this method uses trappy Directory#makeLock API")
public static Lock acquireLock(Directory directory, String lockName, long timeout) throws IOException {
final Lock writeLock = directory.makeLock(lockName);
boolean success = false;
try {
if (writeLock.obtain(timeout) == false) {
throw new LockObtainFailedException("failed to obtain lock: " + writeLock);
}
success = true;
} finally {
if (success == false) {
writeLock.close();
}
}
return writeLock;
}