MySQL server has gone away problem

We have an application written by Ruby on Rails. HTTP server is Unicorn + Nginx. We also use Sidekiq. Database is RDS Auora MySQL with 1 writer and 2 reader instances. Sometimes, I received a message that “Mysql2::Error::ConnectionError: MySQL server has gone away” I googled it and config some attributes of MySQL.

  • wait_timeout: 28800s
  • interactive_timeout 28800s
  • connect_timeout 300s
  • max_allowed_packet 8388608bytes

After set up like that, the situation even worse, beside above error, I also received “MySQL client is not connected”. I watch CPU, freeable memory, connections count. All metrics seem OK and were not overload at all.

DB pool also set up by 5. Puma + Postgresql did well for me in another project. This is the first time I worked with Unicorn. Different from Puma, Unicorn use process and because of that, DB pool may be not a concern.(Correct me if I’m wrong) Some discussion told that mabe Sidekiq thread affect but with 6 workers and 5 pool, 30 connections is good enough for Sidekiq, I think. Beside, I also disconnect db before_fork and establish connection after_fork.

So anyone see problem here ? Am I wrong in setting up Unicorn or MySQL. Thank you for your concern. I appreciate any help.