Skip to content

Commit

Permalink
Fix bug in default connection pool if a disconnect error is raised an…
Browse files Browse the repository at this point in the history
…d the disconnection_proc also raises an error
  • Loading branch information
jeremyevans committed Jul 22, 2011
1 parent 1ffef82 commit 8b1f79f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/sequel/connection_pool/threaded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/core/connection_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 8b1f79f

Please sign in to comment.