Permalink
Browse files

deal with removing connections associated with the current thread

  • Loading branch information...
1 parent 17ff88c commit e060cf01a5e05bc6eaeee90b8c421d2aa6435b7c @tenderlove tenderlove committed Dec 30, 2011
View
7 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -222,6 +222,13 @@ def checkin(conn)
def remove(conn)
synchronize do
@connections.delete conn
+
+ # FIXME: we might want to store the key on the connection so that removing
+ # from the reserved hash will be a little easier.
+ thread_id = @reserved_connections.keys.find { |k|
+ @reserved_connections[k] == conn
+ }
+ @reserved_connections.delete thread_id if thread_id
end
end
View
8 activerecord/test/cases/connection_pool_test.rb
@@ -37,6 +37,14 @@ def test_remove_connection
conn.close
end
+ def test_remove_connection_for_thread
+ conn = @pool.connection
+ @pool.remove conn
+ assert_not_equal(conn, @pool.connection)
+ ensure
+ conn.close
+ end
+
def test_active_connection?
assert !@pool.active_connection?
assert @pool.connection

0 comments on commit e060cf0

Please sign in to comment.