This project is archived and is in readonly mode.

#1335 ✓resolved

Connection pool creating a new connection for every http request

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

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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by