Skip to content
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

lock_prefix argument is not respected #850

Open
adamcreekroad opened this issue Jul 18, 2024 · 1 comment
Open

lock_prefix argument is not respected #850

adamcreekroad opened this issue Jul 18, 2024 · 1 comment

Comments

@adamcreekroad
Copy link
Contributor

Describe the bug

Currently, the lock_prefix configuration option is ignored, and all created locks currently all use the global default uniquejobs.

I believe this to be a regression from #774, specifically this LOC. The way the code is now, it always sets the prefix to the global default, rather than respecting a specific job's configuration.

I've created an isolated case that displays the broken behavior and proves that LOC is the perpetrator:

require "sidekiq"
require "sidekiq-unique-jobs"

Sidekiq.configure_server do |config|
  config.redis = { url: "redis://localhost:6379/15" }

  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: "redis://localhost:6379/15" }
  config.client_middleware do |chain|
    chain.add SidekiqUniqueJobs::Middleware::Client
  end
end

class MyJob
  include Sidekiq::Worker
  sidekiq_options lock: :until_and_while_executing, lock_prefix: :foo
end

Sidekiq::Queue.new.each(&:delete)

MyJob.perform_async

puts(SidekiqUniqueJobs::Digests.new.entries)

Sidekiq::Queue.new.each(&:delete)

module SidekiqUniqueJobs
  module Job
    def add_lock_prefix(item)
      item[LOCK_PREFIX] ||= SidekiqUniqueJobs.config.lock_prefix
    end
  end
end 

MyJob.perform_async

puts(SidekiqUniqueJobs::Digests.new.entries)

Sidekiq::Queue.new.each(&:delete)

The output shows the initial lock contains the wrong prefix, while after the monkey-patch it uses the correct configuration:
Screenshot 2024-07-18 154315

Expected behavior

The created lock should use the prefix set via the lock_prefix configuration option.

Current behavior

The created lock always uses the global default prefix.

Additional context
I don't know the full context behind that aforementioned PR and what the root cause is, so I'm not sure if the fix is as simple as the monkey-patch in my example.

@Ataraxic
Copy link

Hey just wanted to raise that I ran into this issue with this running on version 8.0.9 . I believe this issue is likely still happening in 8.0.10 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants