views:

234

answers:

2

Hi all,

We're running a JRuby on Rails application on Jetty, and having reached the staging server prior to launch have suddenly hit a problem with our JDBC connections being abandoned. Here's a lovely stacktrace to illustrate:

Last packet sent to the server was 12 ms ago.

STACKTRACE:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)

From reading around my understanding is that MySQL is killing our connection pool over a period of time due to inactivity (which makes sense as staging is under very light load right now). It's running under JRuby 1.3.1 with the following gems:

activerecord-jdbc-adapter (0.9.1) activerecord-jdbcmysql-adapter (0.9.1) jdbc-mysql (5.0.4)

I'm assuming that I probably need to set some JDBC configuration somehow to ensure the connections are kept alive or recycled properly, but I need some help finding out where to look. Can anyone furnish me with the details?

Thanks, Steve

+1  A: 

Hi Steven. This is probably due to the wait_timeout setting. You could try increasing it to something very large, but that assumes you have administrative access on the database server.

I've never used JRuby or Rails. But in "regular" Java, the way I would solve this is to use a connection pool which automatically recycles idle connections. For example, c3p0 has a maxIdleTime setting that controls this.

EDIT: Just for fun, I did a Google search on "activerecord idle connection" and I got a few hits. Here's one: http://groups.google.com/group/sinatrarb/browse%5Fthread/thread/54138bfedac59849

Apparently there is a method called ActiveRecord::Base.verify_active_connections! that you can use. I make no guarantees whatsoever about this solution :-). IANARP (I am not a Ruby programmer).

Matt Solnit
A: 

Either Rails or our ActiveRecord-JDBC code should probably provide for a periodic connection ping or idle-time teardown. Connections being culled by the server is a standard case any connection pooling implementation should be able to handle.

I'd say file a bug with ActiveRecord-JDBC on kenai.com, but first ask on JRuby ML if anyone else has found a solid solution for this.

Charles Oliver Nutter