You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2016/07/28 00:51:51 UTC

[2/3] curator git commit: CURATOR-337: Do not attempt to release a mutex unless it has actually been acquired

CURATOR-337: Do not attempt to release a mutex unless it has actually been acquired


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/6cebfc13
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/6cebfc13
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/6cebfc13

Branch: refs/heads/CURATOR-3.0
Commit: 6cebfc13ccdcd9cb2a5b576fa369b957e651752a
Parents: ba85368
Author: Mark Payne <ma...@hotmail.com>
Authored: Wed Jul 27 20:23:13 2016 -0400
Committer: Mark Payne <ma...@hotmail.com>
Committed: Wed Jul 27 20:23:13 2016 -0400

----------------------------------------------------------------------
 .../recipes/leader/LeaderSelector.java          | 21 +++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/6cebfc13/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
----------------------------------------------------------------------
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 @@ public class LeaderSelector implements Closeable
         }
         finally
         {
-            hasLeadership = false;
-            try
-            {
-                mutex.release();
-            }
-            catch ( Exception e )
+            if ( hasLeadership )
             {
-                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
+                }
             }
         }
     }