CURATOR-337: Do not attempt to release a mutex unless it has actually been acquired
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
index ec33533..c177302 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
@@ -419,16 +419,19 @@
}
finally
{
- hasLeadership = false;
- try
+ if ( hasLeadership )
{
- mutex.release();
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- log.error("The leader threw an exception", e);
- // ignore errors - this is just a safety
+ hasLeadership = false;
+ try
+ {
+ mutex.release();
+ }
+ catch ( Exception e )
+ {
+ ThreadUtils.checkInterrupted(e);
+ log.error("The leader threw an exception", e);
+ // ignore errors - this is just a safety
+ }
}
}
}