Skip to content

Commit 069c3c1

Browse files
committed
prevent deadlocks with the connection pool
1 parent dcece34 commit 069c3c1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/resque/connection_pool.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def checkout
3434
def checkin(conn)
3535
@lock.synchronize do
3636
conns[conn] = false
37+
@cv.broadcast
3738
end
3839
end
3940

test/connection_pool_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,25 @@ def method_missing(meth, *args, &block)
9393

9494
assert cp.checkout, "Connection should not be nil"
9595
end
96+
97+
it "avoids deadlocks" do
98+
cp = ConnectionPool.new(REDIS_URL, 2)
99+
cp.with_connection {|conn| conn.rpush(:foo, "hello") }
100+
101+
threads = []
102+
5.times do
103+
threads << Thread.new do
104+
cp.with_connection do |conn|
105+
conn.blpop(:foo, 1)
106+
end
107+
end
108+
end
109+
110+
begin
111+
threads.each {|t| t.join }
112+
rescue Exception => e
113+
refute_equal "fatal", e.class.to_s, e.message
114+
end
115+
end
96116
end
97117
end

0 commit comments

Comments
 (0)