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

Fix(namespace): Prevent self-conflict when redis-namespace is present #732

Merged
merged 3 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ detectors:
- SidekiqUniqueJobs::Lock#del
- SidekiqUniqueJobs::Lock#lock
- SidekiqUniqueJobs::Lock::WhileExecuting#execute
- SidekiqUniqueJobs::Locksmith#brpoplpush
- SidekiqUniqueJobs::Locksmith#enqueue
- SidekiqUniqueJobs::Locksmith#lock_sync
- SidekiqUniqueJobs::Locksmith#set_lock_info
Expand Down Expand Up @@ -91,6 +92,7 @@ detectors:
- Sidekiq#self.use_options
- Sidekiq::Worker::ClassMethods#use_options
- SidekiqUniqueJobs::LockArgs#default_job_options
- SidekiqUniqueJobs::Locksmith#brpoplpush
- SidekiqUniqueJobs::Logging#logger_respond_to_with_context?
- SidekiqUniqueJobs::OnConflict::Reject#deadset_kill?
- SidekiqUniqueJobs::Orphans::RubyReaper#active?
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_develop.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake", "13.0.3"
gem "redis-namespace"
gem "reek", ">= 5.3"
gem "rspec"
gem "rspec-benchmark"
Expand Down
13 changes: 11 additions & 2 deletions lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,15 @@ def pop_queued(conn, wait = 1)
# @api private
#
def brpoplpush(conn, wait)
# passing timeout 0 to brpoplpush causes it to block indefinitely
raise InvalidArgument, "wait must be an integer" unless wait.is_a?(Integer)
return conn.brpoplpush(key.queued, key.primed, wait) if conn.class.to_s == "Redis::Namespace"

# passing timeout 0 to brpoplpush causes it to block indefinitely
conn.brpoplpush(key.queued, key.primed, timeout: wait)
if VersionCheck.satisfied?(redis_version, ">= 6.2.0") && conn.respond_to?(:blmove)
conn.blmove(key.queued, key.primed, "RIGHT", "LEFT", timeout: wait)
else
conn.brpoplpush(key.queued, key.primed, timeout: wait)
end
end

#
Expand Down Expand Up @@ -370,5 +375,9 @@ def lock_info
TIME => now_f,
)
end

def redis_version
@redis_version ||= SidekiqUniqueJobs.config.redis_version
end
end
end
4 changes: 4 additions & 0 deletions spec/integration/until_and_while_executing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

unless ENV.fetch("CI", false)
# require "redis-namespace"

RSpec.describe "SidekiqUniqueJobs::Lock::UntilAndWhileExecuting" do
before do
digests.delete_by_pattern("*")
Expand All @@ -20,10 +22,12 @@
end

Sidekiq.configure_server do |config|
# config.redis = { port: 21_212, db: 9, namespace: "foo" }
config.redis = { port: 21_212, db: 9 }
end

Sidekiq.configure_client do |config|
# config.redis = { port: 21_212, db: 9, namespace: "foo" }
config.redis = { port: 21_212, db: 9 }
end

Expand Down