mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Failsafe on Redis error replies in RedisCacheStoreProxy.
RedisCacheStoreProxy will blow up when RedisCacheStore raises a CommandError exception. In fact, by default the proxied store only handles BaseConnectionError exceptions, but will let bubble up any other type of exception from the underlying client. This pull request uses the same approach from RedisProxy, where store operations are wrapped in a `rescuing` block that rescues and ignores BaseError exceptions (the most generic exception class that can be raised by the Redis client).
This commit is contained in:
parent
d1b71da182
commit
dd6c09e581
1 changed files with 22 additions and 6 deletions
|
|
@ -15,17 +15,33 @@ module Rack
|
|||
#
|
||||
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
|
||||
# the counter. After that we continue using the original RedisCacheStore#increment.
|
||||
if options[:expires_in] && !read(name)
|
||||
write(name, amount, options)
|
||||
rescuing do
|
||||
if options[:expires_in] && !read(name)
|
||||
write(name, amount, options)
|
||||
|
||||
amount
|
||||
else
|
||||
super
|
||||
amount
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def read(*_args)
|
||||
rescuing { super }
|
||||
end
|
||||
|
||||
def write(name, value, options = {})
|
||||
super(name, value, options.merge!(raw: true))
|
||||
rescuing do
|
||||
super(name, value, options.merge!(raw: true))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rescuing
|
||||
yield
|
||||
rescue Redis::BaseError
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue