aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-12 11:51:28 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-12 11:58:38 -0700
commit5f26ce699f9e695c434cbff20626a9ff4d3114e4 (patch)
treea4e0480f3c908aa480c44a8605f41860b6b68de9 /activerecord
parentda0595d7d796e52b950d2c60cb60e58c18b70791 (diff)
downloadrails-5f26ce699f9e695c434cbff20626a9ff4d3114e4.tar.gz
rails-5f26ce699f9e695c434cbff20626a9ff4d3114e4.tar.bz2
rails-5f26ce699f9e695c434cbff20626a9ff4d3114e4.zip
make sure connections returned after close are marked as in_use
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb16
-rw-r--r--activerecord/test/cases/connection_pool_test.rb10
2 files changed, 26 insertions, 0 deletions
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 4787bd2cbf..f198be0802 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -269,11 +269,27 @@ connection. For example: ActiveRecord::Base.connection.close
conn.expire
@queue.signal
end
+
+ release conn
end
end
private
+ def release(conn)
+ thread_id = nil
+
+ if @reserved_connections[current_connection_id] == conn
+ thread_id = current_connection_id
+ else
+ thread_id = @reserved_connections.keys.find { |k|
+ @reserved_connections[k] == conn
+ }
+ end
+
+ @reserved_connections.delete thread_id if thread_id
+ end
+
def new_connection
ActiveRecord::Base.send(spec.adapter_method, spec.config)
end
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index dd0acfdd03..5cecfa90e7 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -31,6 +31,16 @@ module ActiveRecord
pool.connections.find_all(&:in_use?)
end
+ def test_checkout_after_close
+ connection = pool.connection
+ assert connection.in_use?
+
+ connection.close
+ assert !connection.in_use?
+
+ assert pool.connection.in_use?
+ end
+
def test_released_connection_moves_between_threads
thread_conn = nil