Fix compatibility with redis-rb 4.6.0#192
Merged
byroot merged 1 commit intoresque:masterfrom Mar 7, 2022
Merged
Conversation
5dccf88 to
b80aefa
Compare
Fix: resque#191 Fix: redis/redis-rb#1088 In redis-rb 4.6.0, the object yielded by `multi` and `pipelined` is an unsynchronized `PipelinedConnection` object. This changed opened a thread safety issue in Redis::Namespace: - T1: `redis.multi do`, sets `Namespace#redis = PipelinedConnection` - T2: any command called before T1 exists the `multi` block is called on the pipelined connection
b80aefa to
7f76249
Compare
|
Thank you @casperisfine . I've tested your fix locally and it does solve the problem. # Gemfile
source 'https://rubygems.org'
gem 'redis', path: './redis-rb'
#gem 'redis', '4.5.1'
gem 'redis-namespace', path: './redis-namespace' # local copy of this PR branch
#gem 'redis-namespace'# reproduce_bug.rb
require 'bundler/setup'
require 'redis'
require 'redis-namespace'
puts "Redis gem version: #{Redis::VERSION}"
key = 'a_key'
threads = []
redis = Redis.new(timeout: 5)
redis = Redis::Namespace.new('my-namespace', redis: redis)
index = 0
while true do
100.times do
threads << Thread.new do
100.times do
redis.multi do |transaction|
transaction.incr(key)
transaction.expire(key, 360)
end
end
end
end
threads.each(&:join)
puts "It works! Iteration: #{index}"
index += 1
endOutput: |
nevans
added a commit
to nevans/resque
that referenced
this pull request
Jun 21, 2022
Re-using the connection is no longer supported. Instead, the block var must be used. See also: * redis/redis-rb#1059 * resque/redis-namespace#192
iloveitaly
pushed a commit
to resque/resque
that referenced
this pull request
Jun 22, 2022
Re-using the connection is no longer supported. Instead, the block var must be used. See also: * redis/redis-rb#1059 * resque/redis-namespace#192
jwoodrow
pushed a commit
to moonproject/resque
that referenced
this pull request
Aug 5, 2022
Re-using the connection is no longer supported. Instead, the block var must be used. See also: * redis/redis-rb#1059 * resque/redis-namespace#192
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: #191
Fix: redis/redis-rb#1069
Fix: redis/redis-rb#1088
In redis-rb 4.6.0, the object yielded by
multiandpipelinedis an unsynchronized
PipelinedConnectionobject.This changed opened a thread safety issue in Redis::Namespace:
redis.multi do, setsNamespace#redis = PipelinedConnectionmultiblock is called on the pipelined connectioncc @ArturT, @sergio91pt (extra testing welcome)