Class: RooOnRails::Rack::SafeTimeouts
- Inherits:
-
Object
- Object
- RooOnRails::Rack::SafeTimeouts
- Defined in:
- lib/roo_on_rails/rack/safe_timeouts.rb
Overview
Cleans up Rails database connections on timeouts, before they’re returned to the pool.
In particular, this clears the prepared statement cache, which can become corrupted as ActiveRecord isn’t interrupt-safe.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ SafeTimeouts
constructor
A new instance of SafeTimeouts.
Constructor Details
#initialize(app) ⇒ SafeTimeouts
Returns a new instance of SafeTimeouts.
15 16 17 |
# File 'lib/roo_on_rails/rack/safe_timeouts.rb', line 15 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/roo_on_rails/rack/safe_timeouts.rb', line 19 def call(env) @app.call(env) rescue ::Rack::Timeout::Error, ::Rack::Timeout::RequestTimeoutException Rails.logger.warn('Clearing ActiveRecord connection cache due to timeout') ActiveRecord::Base.connection.clear_cache! raise end |