jruby activerecord-jdbc-adapter connection pool is not reconnecting after socketTimeout

388 Views Asked by At

I am using jruby and mysql2 gem version mysql2 (0.3.11). My database.yml looks something like this.

production:

  <<: *common
  database: database
  host: host
  port: 3306
  username: username
  password: ********
  pool: 5
  pool_initial: true
  checkout_timeout: 0.3
     properties:
     connectTimeout: 250
     socketTimeout: 90000 

One of the queries exceeded socket timeout of 90 seconds in my case and after that, each of the requests that are using same connection from the pool started failing. I am expecting mysql2 should reconnect but It is not reconnecting in my case. I looked at the documentation but could not find anything.

Edit1: I did little bit of more debuging and I am using activerecord-jdbc-adapter in production instead of mysql2 gem and I tried fixing the problem using autoReconnect: true but looks like it is not recommended as it can mess up with consistency. http://pages.citebite.com/p4x3a0r8pmhm

Edit2: Version - jruby(1.7.4) and activerecord-jdbc-adapter (1.2.9.1)

1

There are 1 best solutions below

1
On

first of all if you're under JRuby you can not be using mysql2 gem.

you're using a JDBC driver (jdbc-mysql gem - you identified that correctly).

reconnect: true should have worked (maps to autoReconnect: true property), without the reconnect AR's pool likely doesn't detect an invalid connection properly. this might actually depend from Rails version to version and might also be considered a activerecord-jdbc-adapter bug.