Skip to content

Commit 6f93985

Browse files
author
Aaron Patterson and Terence Lee
committed
fix deadlock connection checkout raises an exception
1 parent 335c8b6 commit 6f93985

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/resque/connection_pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def with_connection
3030
conn = checkout
3131
yield(conn)
3232
ensure
33-
checkin(conn)
33+
checkin(conn) if conn
3434
end
3535

3636
private

test/connection_pool_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
module Resque
44
describe ConnectionPool do
5+
it "with_conneciton does not deadlock on checkout exceptions" do
6+
cp = Class.new(ConnectionPool) {
7+
def checkout
8+
raise "omg"
9+
end
10+
}.new(REDIS_URL, 5)
11+
e = assert_raises(RuntimeError) do
12+
cp.with_connection { }
13+
end
14+
assert_equal 'omg', e.message
15+
end
16+
517
it "takes a URL" do
618
cp = ConnectionPool.new(REDIS_URL, 5)
719
assert_equal 5, cp.size

0 commit comments

Comments
 (0)