Skip to content

Commit

Permalink
Re-raise Redis connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
panozzaj committed Jun 2, 2022
1 parent 05a9e64 commit a60a2fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/redlock/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ def lock(resource, val, ttl, allow_new_lock)
recover_from_script_flush do
@redis.with { |conn| conn.evalsha Scripts::LOCK_SCRIPT_SHA, keys: [resource], argv: [val, ttl, allow_new_lock] }
end
rescue Redis::BaseConnectionError
false
end

def unlock(resource, val)
Expand Down
12 changes: 7 additions & 5 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ def redis.with
end

context 'when a server goes away' do
it 'does not raise an error on connection issues' do
# We re-route the lock manager to a (hopefully) non-existent Redis URL.
it 'raises an error on connection issues' do
# Set lock manager to a (hopefully) non-existent Redis URL to test error
redis_instance = lock_manager.instance_variable_get(:@servers).first
redis_instance.instance_variable_set(:@redis, unreachable_redis)

expect {
expect(lock_manager.lock(resource_key, ttl)).to be_falsey
}.to_not raise_error
lock_manager.lock(resource_key, ttl)
}.to raise_error(Redis::CannotConnectError)
end
end

Expand All @@ -259,7 +259,9 @@ def redis.with
redis_instance = lock_manager.instance_variable_get(:@servers).first
old_redis = redis_instance.instance_variable_get(:@redis)
redis_instance.instance_variable_set(:@redis, unreachable_redis)
expect(lock_manager.lock(resource_key, ttl)).to be_falsey
expect {
lock_manager.lock(resource_key, ttl)
}.to raise_error(Redis::CannotConnectError)
redis_instance.instance_variable_set(:@redis, old_redis)
expect(lock_manager.lock(resource_key, ttl)).to be_truthy
end
Expand Down

0 comments on commit a60a2fb

Please sign in to comment.