Dropped Mysql connection

question

#1

Hi, I got a dropped db connection error: “RubyError: ActiveRecord::StatementInvalid: Mysql2::Error::ConnectionError: MySQL server has gone away”

It happened only once so far, so fairly rare, but all Lambdas were affected and it required a redeploy to fix. I still don’t know why (after redeploy everything was fine). I’ve read in the guides about the shared Lambda context but I’m not familiar enough with it. Any suggestions? Eg, is it worth setting “reconnect: true” in the db config (database.yml)? Any other recommended settings for a production deploy?

I don’t think the issue was too many connections because the number stayes pretty consistent around 15 connections, spiking to 25 max.

Using: mysql2 (0.5.2), activerecord (6.0.0), jets (2.3.4), with an RDS Mysql 5.7.22


#2

This is dependent on how the MySQL server is configured to handle long idle connections. You can also adjust MySQL server settings but it’s better to do what you mentioned. In the config/database.yml use

reconnect: true

Surprised that wasn’t the default in the skeleton database.yml. Updated: https://github.com/tongueroo/jets/pull/401

Here’s some more info https://stackoverflow.com/questions/21594429/database-yml-in-rails-reconnect-set-to-true-or-false


#3

Thanks Tung! Yeah, I wasn’t sure if you added some extra behind-the-scenes functionality to deal with the lambda execution context so I didn’t want to start messing with the connections before checking.