veeqo/activejob-uniqueness

ActiveJob perform_now results in crash when the patch tries to delete the resource

leifcr opened this issue · 1 comments

I saw this when deploying to a live/staging enviroment, as during development, the server was on localhost, and the connection issue will not appear.

To reproduce:
Create a simple job
Use sidekiq
Run redis on non-localhost

Run 'SimpleJob.perform_now'

Strategy is set to until_executed

It will trigger this:

 (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:398:in `rescue in establish_connection'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:379:in `establish_connection'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:115:in `block in connect'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:344:in `with_reconnect'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:114:in `connect'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:417:in `ensure_connected'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:269:in `block in process'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:356:in `logging'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:268:in `process'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/client.rb:161:in `call'
/usr/local/bundle/gems/redis-4.7.1/lib/redis.rb:269:in `block in send_command'
/usr/local/bundle/gems/redis-4.7.1/lib/redis.rb:268:in `synchronize'
/usr/local/bundle/gems/redis-4.7.1/lib/redis.rb:268:in `send_command'
/usr/local/bundle/gems/redis-4.7.1/lib/redis/commands/keys.rb:192:in `del'
/usr/local/bundle/gems/activejob-uniqueness-0.2.4/lib/active_job/uniqueness/lock_manager.rb:13:in `block (2 levels) in delete_lock'
/usr/local/bundle/gems/redlock-1.2.2/lib/redlock/client.rb:152:in `with'
/usr/local/bundle/gems/activejob-uniqueness-0.2.4/lib/active_job/uniqueness/lock_manager.rb:12:in `block in delete_lock'
/usr/local/bundle/gems/activejob-uniqueness-0.2.4/lib/active_job/uniqueness/lock_manager.rb:11:in `each'
/usr/local/bundle/gems/activejob-uniqueness-0.2.4/lib/active_job/uniqueness/lock_manager.rb:11:in `delete_lock'
/usr/local/bundle/gems/activejob-uniqueness-0.2.4/lib/active_job/uniqueness/strategies/base.rb:30:in `unlock'

Not sure how to solve this the best way.

It looks like the parameters for the redlock client isn't passed properly at some point

Closing. The issue was solved buy setting the redlock servers manually.

For others to solve the same issue:
Run this:
rails generate active_job:uniqueness:install

Then set the following in config/initializers/active_job_uniqueness.rb

config.redlock_servers = [ENV['REDIS_URL']]
Make sure to set REDIS_URL in the ci/cd/deployment config you currently have.