Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close lock even if we fail to obtain #11412

Merged
merged 1 commit into from May 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/org/elasticsearch/common/lucene/Lucene.java
Expand Up @@ -189,8 +189,16 @@ public static Lock acquireWriteLock(Directory directory) throws IOException {
@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);
if (writeLock.obtain(timeout) == false) {
throw new LockObtainFailedException("failed to obtain lock: " + writeLock);
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;
}
Expand Down