Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Connection pool creating a new connection for every http request

#1335

Every http request appears to be establishing a new database connection rather than checking connections in and out of the pool.

Each time the application reaches the checkout method in ActiveRecord::ConnectionAdapters::ConnectionPool, both @checked_out.size and @connections.size are always zero, despite there being numerous open connections. This results in the checkout of a new connection for every http request. Although the newly checked out connection is being correctly appended to the list of open connections via the checkout_new_connection method, the @connections list appears to have been emptied by the time a new request is made.

I have been able to reproduce the problem with a fresh rails app in the following environments

  • 2 Windows machines running edge rails with ruby 1.8.6 patch level 111
  • 1 Windows machine running edge rails with ruby 1.8.5 (2006-08-25)
  • 1 Mac OSX machine running edge rails with ruby 1.8.6 patch level 111

Against these environments I have tested with both Oracle and MySQL. The issue is not quite as evident using MySQL because a show processlist reveals that MySQL appears to 'clean up' active connections that are not being used. Thus, with one user hitting the app, the number of connections to MySQL doesn't get beyond roughly 10 before they are 'cleaned up'. Oracle is a different story. The number of connections to the database quickly spirals out of control (as seen via SELECT * FROM v$session;). In fact if not for Oracle we would not have noticed this happening.

Strangely enough, a Redhat machine running edge rails with ruby 1.8.5 (2006-08-25) [x86_64-linux] against Oracle does not reproduce the same error.

Reported by thrillhouse · November 6th, 2008 @ 01:11 AM

State: resolved
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Zyclops
    Zyclops

    I can confirm that this is the case under OSX with MySQL under ruby 1.8.6. Too me it looks like the variable that contains a list of the connections isn't maintaining state between requests.

    November 6th, 2008 @ 10:39 PM

  2. Pratik
  3. Zyclops
    Zyclops

    This only happens in development mode (thanks lifo) and is to do with class reloading.

    In production it works fine.

    In development mode it is an issue since under oracle it causes hundreds of connections to rack up and eventually locks up the database (MySQL is nice since it does some housekeeping and cleans up the connections).

    November 6th, 2008 @ 11:04 PM

  4. Pratik
    Pratik
    • Assigned user set to Pratik

    November 6th, 2008 @ 11:34 PM

  5. Repository
    Repository
    • State changed from new to resolved

    (from [d20955f889223b6035dbc7d61acba9091bf7b7ed]) Don't leave open dangling connections in development mode. [#1335 state:resolved] http://github.com/rails/rails/co...

    November 7th, 2008 @ 11:35 PM

  6. thrillhouse
    thrillhouse

    That's fixed it. Well done and thanks for your work guys.

    November 9th, 2008 @ 10:53 PM