aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2008-10-02 22:59:03 +0300
committerMichael Koziarski <michael@koziarski.com>2008-10-04 17:48:13 +0200
commit6080b73b1cf6c9ff969b81751a1e5d26d7633a32 (patch)
tree20ce3433da390db10f9dacb6ea2d63a1c5d4d4a9 /actionpack
parent834361145a805b5077f962dc2e67a0a9ea882535 (diff)
downloadrails-6080b73b1cf6c9ff969b81751a1e5d26d7633a32.tar.gz
rails-6080b73b1cf6c9ff969b81751a1e5d26d7633a32.tar.bz2
rails-6080b73b1cf6c9ff969b81751a1e5d26d7633a32.zip
call clear_active_connections! in :after_dispatch to give pooled connections back
This fixes connection pool exhaustion for web servers which create new thread per connection (e.g. Webrick). integration.rb changes are required to keep test transaction active for several requests. Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1171 state:committed]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/dispatcher.rb16
-rw-r--r--actionpack/lib/action_controller/integration.rb2
2 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb
index bdae5f9d86..106d9605af 100644
--- a/actionpack/lib/action_controller/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatcher.rb
@@ -20,6 +20,7 @@ module ActionController
end
if defined?(ActiveRecord)
+ after_dispatch :checkin_connections
before_dispatch { ActiveRecord::Base.verify_active_connections! }
to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
end
@@ -145,6 +146,21 @@ module ActionController
Base.logger.flush
end
+ def mark_as_test_request!
+ @test_request = true
+ self
+ end
+
+ def test_request?
+ @test_request
+ end
+
+ def checkin_connections
+ # Don't return connection (and peform implicit rollback) if this request is a part of integration test
+ return if test_request?
+ ActiveRecord::Base.clear_active_connections!
+ end
+
protected
def handle_request
@controller = Routing::Routes.recognize(@request)
diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb
index a98c1af7f9..fc473c269c 100644
--- a/actionpack/lib/action_controller/integration.rb
+++ b/actionpack/lib/action_controller/integration.rb
@@ -276,7 +276,7 @@ module ActionController
ActionController::Base.clear_last_instantiation!
env['rack.input'] = data.is_a?(IO) ? data : StringIO.new(data || '')
- @status, @headers, result_body = ActionController::Dispatcher.new.call(env)
+ @status, @headers, result_body = ActionController::Dispatcher.new.mark_as_test_request!.call(env)
@request_count += 1
@controller = ActionController::Base.last_instantiation