diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-29 15:42:32 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-29 15:42:32 -0700 |
commit | 3b2a032677a2261499aa5d2de019f31f1173a858 (patch) | |
tree | 6999aa919a2c10c7833b9b29b4097bcb92fc04d4 /activerecord | |
parent | e5246092d1ce30961af4f7d9b5ad86071298cf1c (diff) | |
download | rails-3b2a032677a2261499aa5d2de019f31f1173a858.tar.gz rails-3b2a032677a2261499aa5d2de019f31f1173a858.tar.bz2 rails-3b2a032677a2261499aa5d2de019f31f1173a858.zip |
clearing active connections in the ConnectionManagement middleware if an exception happens
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/connection_management_test.rb | 7 |
2 files changed, 10 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 5e12f80263..45900d27dc 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -446,6 +446,9 @@ module ActiveRecord status, headers, body = @app.call(env) [status, headers, Proxy.new(body, env.key?('rack.test'))] + rescue + ActiveRecord::Base.clear_active_connections! + raise end end end diff --git a/activerecord/test/cases/connection_management_test.rb b/activerecord/test/cases/connection_management_test.rb index 3734f8e5f0..0d4a9a287e 100644 --- a/activerecord/test/cases/connection_management_test.rb +++ b/activerecord/test/cases/connection_management_test.rb @@ -57,6 +57,13 @@ module ActiveRecord assert ActiveRecord::Base.connection_handler.active_connections? end + def test_connections_closed_if_exception + app = Class.new(App) { def call(env); raise; end }.new + explosive = ConnectionManagement.new(app) + assert_raises(RuntimeError) { explosive.call(@env) } + assert !ActiveRecord::Base.connection_handler.active_connections? + end + test "doesn't clear active connections when running in a test case" do @env['rack.test'] = true @management.call(@env) |