-
-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locks not removed after worker finishes #758
Comments
I had this exact same issue!
I noticed this old issue that reported the same thing: #677 The reply was "I messed up client and server midlewares". So I checked my own configuration, and low and behold, I had the exact same issue. The configuration for Having it backwards like that, caused Suggest you check your own configuration, since you haven't specified it above. |
Thanks for the comment! This is my setup: # frozen_string_literal: true
require 'sidekiq/api'
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] }
config.logger = Logger.new(STDOUT)
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
config.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
end
SidekiqUniqueJobs::Server.configure(config)
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'] }
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
end
# prevent dying jobs from littering uniqueness keys
Sidekiq.configure_server do |config|
config.death_handlers << ->(job, _ex) do
digest = job['lock_digest']
SidekiqUniqueJobs::Digests.new.delete_by_digest(digest) if digest
end
end I don't think that this is backwards — at least I have the client middleware where it says client … |
Still observing this, and it is causing major headaches. My worker is drained but I still see the digests:
|
Hi @slhck, If you want the jobs to clear as they are performed, you'd have to add the following: Sidekiq::Testing.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
end Reference: https://github.com/sidekiq/sidekiq/wiki/Testing#testing-server-middleware. It is flimsy at best to test uniqueness and should be tested in the gem rather than in your code. In my projects, I usually turn off sidekiq unique jobs for the rails test environment. |
Thanks! Adding this do I am aware of the hesitancy to add explicit testing, and I've read the README section on it. Admittedly, I didn't fully grasp it. The background issue is that I need some business logic tested. It somewhat depends on jobs being unique, and a specific amount of workers being instantiated. For instance, I want to ensure that when data comes in with a particular sequence, the workers are launched correctly (or prevented from being launched again if not needed). It has been hard to find the right lock and conflict strategies for some workers without trial and error, and there have been issues in production — so we'd like to bake this into the test suite. |
If it is essential to business, you should test that everything works correctly. |
Describe the bug
Digests (locks) remain in redis even though workers have finished.
Expected behavior
I expect the locks to be gone so I can trigger a worker again.
Current behavior
I run some tests where the attribute
finished_at
should be calculated on a model. In the test this will be done once, initially, when the record is created, and later, when the record is updated and a method is called to re-calculate the attribute.The first time, the worker runs and completes fine. However, after completing, the digests remain and I cannot call the re-calculation method again.
Worker class
Config
The Test
I see that in Redis, there are the locks:
And the info shows the correct args:
But: When I manually run
SidekiqUniqueJobs::Orphans::Reaper.call
after the first.drain
method of the worker, the test passes as expected.I wonder: shouldn't the lock be removed when the job finishes?
Context
Ruby 3.1.4p223 with Gems:
The text was updated successfully, but these errors were encountered: