diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 3f54a98380bc98907d9dc403281f0b24ceb692cc..a88c9e2c4b5d3f841be8ddc683f8601935ad7e02 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/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 diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index d4d0f6258df65aebabed0400662be13e2cdb81ef..10f91d7eb0e351a8157fb324d9237202ccd99598 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/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