From 8b1f79f44ae49e7bf3ba75957e1ec94534ee47ed Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 22 Jul 2011 14:47:19 -0700 Subject: [PATCH] Fix bug in default connection pool if a disconnect error is raised and the disconnection_proc also raises an error --- CHANGELOG | 2 ++ lib/sequel/connection_pool/threaded.rb | 5 +++-- spec/core/connection_pool_spec.rb | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e3c506a504..7a0f5ea012 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ === HEAD +* Fix bug in default connection pool if a disconnect error is raised and the disconnection_proc also raises an error (jeremyevans) + * Disallow eager loading via eager of many_*_many associations with :eager_graph option (jeremyevans) * Major speedup in dataset creation (jeremyevans) diff --git a/lib/sequel/connection_pool/threaded.rb b/lib/sequel/connection_pool/threaded.rb index e9441c97b3..1c18311752 100644 --- a/lib/sequel/connection_pool/threaded.rb +++ b/lib/sequel/connection_pool/threaded.rb @@ -83,9 +83,10 @@ def hold(server=nil) end yield conn rescue Sequel::DatabaseDisconnectError - @disconnection_proc.call(conn) if @disconnection_proc && conn - @allocated.delete(t) + oconn = conn conn = nil + @disconnection_proc.call(oconn) if @disconnection_proc && oconn + @allocated.delete(t) raise ensure sync{release(t)} if conn diff --git a/spec/core/connection_pool_spec.rb b/spec/core/connection_pool_spec.rb index d3c05bf33a..51e5cb1db1 100644 --- a/spec/core/connection_pool_spec.rb +++ b/spec/core/connection_pool_spec.rb @@ -245,6 +245,12 @@ def value t.join end + it "should not add a disconnected connection back to the pool if the disconnection_proc raises an error" do + pool = Sequel::ConnectionPool.get_pool(@cp_opts.merge(:max_connections=>1, :pool_timeout=>0, :disconnection_proc=>proc{|c| raise Sequel::Error})) {@invoked_count += 1} + proc{pool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::Error) + pool.available_connections.length.should == 0 + end + specify "should let five threads simultaneously access separate connections" do cc = {} threads = []