Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Probable fix for #51, more aggressive cleanup of lock state

Basically runs cleanup if we're exiting the lock method and we didn't
acquire the lock (based on @locked), which is what we actually *mean*
  • Loading branch information...
commit 80b477a92e76323cdc9f2a6fb6accd722716da16 1 parent ad4d101
@slyphon slyphon authored
View
12 lib/zk/locker/exclusive_locker.rb
@@ -54,9 +54,10 @@ def lock_with_opts_hash(opts)
elsif lock_opts.blocking?
block_until_write_lock!(:timeout => lock_opts.timeout)
else
- cleanup_lock_path!
false
end
+ ensure
+ cleanup_lock_path! unless @mutex.synchronize { @locked }
end
# the node that is next-lowest in sequence number to ours, the one we
@@ -92,15 +93,6 @@ def block_until_write_lock!(opts={})
@node_deletion_watcher.block_until_deleted(opts)
rescue WeAreTheLowestLockNumberException
- rescue ZK::Exceptions::LockWaitTimeoutError
- # in the case of a timeout exception, we need to ensure the lock
- # path is cleaned up, since we're not interested in acquisition
- # anymore
- logger.warn { "got ZK::Exceptions::LockWaitTimeoutError, cleaning up lock path" }
- cleanup_lock_path!
- raise
- ensure
- logger.debug { "block_until_deleted returned" }
end
@mutex.synchronize { @locked = true }
View
11 lib/zk/locker/shared_locker.rb
@@ -91,11 +91,10 @@ def lock_with_opts_hash(opts)
elsif lock_opts.blocking?
block_until_read_lock!(:timeout => lock_opts.timeout)
else
- # we didn't get the lock, and we're not gonna wait around for it, so
- # clean up after ourselves
- cleanup_lock_path!
false
end
+ ensure
+ cleanup_lock_path! unless @mutex.synchronize { @locked }
end
def block_until_read_lock!(opts={})
@@ -109,12 +108,6 @@ def block_until_read_lock!(opts={})
end
@node_deletion_watcher.block_until_deleted(opts)
- rescue ZK::Exceptions::LockWaitTimeoutError
- # in the case of a timeout exception, we need to ensure the lock
- # path is cleaned up, since we're not interested in acquisition
- # anymore
- cleanup_lock_path!
- raise
rescue NoWriteLockFoundException
# next_lowest_write_lock_name may raise NoWriteLockFoundException,
# which means we should not block as we have the lock (there is nothing to wait for)
Please sign in to comment.
Something went wrong with that request. Please try again.