Merge pull request #11412 from s1monw/close_lock
Close lock even if we fail to obtain
This commit is contained in:
commit
a7779d8e1d
|
@ -189,8 +189,16 @@ public class Lucene {
|
||||||
@SuppressForbidden(reason = "this method uses trappy Directory#makeLock API")
|
@SuppressForbidden(reason = "this method uses trappy Directory#makeLock API")
|
||||||
public static Lock acquireLock(Directory directory, String lockName, long timeout) throws IOException {
|
public static Lock acquireLock(Directory directory, String lockName, long timeout) throws IOException {
|
||||||
final Lock writeLock = directory.makeLock(lockName);
|
final Lock writeLock = directory.makeLock(lockName);
|
||||||
if (writeLock.obtain(timeout) == false) {
|
boolean success = false;
|
||||||
throw new LockObtainFailedException("failed to obtain lock: " + writeLock);
|
try {
|
||||||
|
if (writeLock.obtain(timeout) == false) {
|
||||||
|
throw new LockObtainFailedException("failed to obtain lock: " + writeLock);
|
||||||
|
}
|
||||||
|
success = true;
|
||||||
|
} finally {
|
||||||
|
if (success == false) {
|
||||||
|
writeLock.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return writeLock;
|
return writeLock;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue