Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ConnectionManagement middleware drains connection pool when Exceptions are raised #11497

Closed
orslumen opened this Issue Jul 18, 2013 · 3 comments

Comments

Projects
None yet
4 participants

As ActiveRecord::ConnectionAdapters::ConnectionManagement middleware does not rescue from Exception (but only from StandardError), the Connection Pool quickly runs out of connections when multiple erroneous Requests come in right after each other.

class TestController < ActionController::Base
  def eat_connection
    # do something with the DB
    raise Exception('lost a connection')
  end

  def release_all_connections
    head :ok
  end
end

Call /test/eat_connection as many times as you have connections in your pool and the application becomes unresponsive, until the connections timeout and are returned to the pool.

Call /test/eat_connection a few times, followed by /test/release_all_connections and the entire pool becomes available again. This is probably what happens with most applications, but it is risky imo that someone who knows how to cause an Exception could potentially bring down the entire application.

Was it a conscious choice to write rescue instead of rescue Exception?

Member

senny commented Jul 19, 2013

The relevant commit is 3b2a032 . It could be an oversight. Let's wait for @tenderlove to elaborate.

Contributor

thedarkone commented Jul 19, 2013

Yep, plain rescue not catching all exceptions has bitten me multiple times :( (wish Matz wouldn't have made it this way). We should check the rest of the Rails code base for any "naked" rescue clauses.

Owner

tenderlove commented Jul 21, 2013

Yep, this is a bug. We need to rescue from Exception rather than a naked rescue.

@vipulnsward vipulnsward added a commit to vipulnsward/rails that referenced this issue Jul 22, 2013

@vipulnsward vipulnsward rescue from all exceptions in `ConnectionManagement#call`
Fixes #11497

As `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware does not rescue from Exception (but only from StandardError),
the Connection Pool quickly runs out of connections when multiple erroneous Requests come in right after each other.

Recueing from all exceptions and not just StandardError, fixes this behaviour.
0b6c1f0

@drogus drogus closed this in #11538 Jul 22, 2013

@thedarkone thedarkone added a commit to thedarkone/rails that referenced this issue Aug 6, 2013

@thedarkone thedarkone "Naked" rescue clauses only catch StandardError subclasses.
Similar to #11497.
a0907bb

@ehtb ehtb added a commit to ehtb/rails that referenced this issue Aug 7, 2013

@thedarkone @ehtb thedarkone + ehtb "Naked" rescue clauses only catch StandardError subclasses.
Similar to #11497.
243dae7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment