Skip to content

Commit

Permalink
Update semaphore redis to initialize a new conn
Browse files Browse the repository at this point in the history
The redis-semaphore gem advises [against reusing the redis connection across threads](dv/redis-semaphore#18) because it causes a Deadlock. We actually experience this and the solution was to initialize a new redis connection when checking for the semaphore.

I additionally added a staleness check to avoid locking everything forever should the semaphore hang for some other reason.
  • Loading branch information
bbonamin committed Sep 5, 2018
1 parent c91639c commit ca8f05e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sidekiq-rate-limiter/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def limit(work)
}

Sidekiq.redis do |conn|
s = Redis::Semaphore.new(:sidekiq_rate_limit_exceeded_check, redis: conn)
s = Redis::Semaphore.new(:sidekiq_rate_limit_exceeded_check, redis: Sidekiq::RedisConnection.create, stale_client_timeout: 60)
lim = Limit.new(conn, options)
limit_exceeded = nil

Expand Down

0 comments on commit ca8f05e

Please sign in to comment.