ruby-amqp / hutch

A system for processing messages from RabbitMQ.
https://gocardless.com/blog/hutch-inter-service-communication-with-rabbitmq/
MIT License
855 stars 137 forks source link

Handing database connection timeouts #354

Closed igatto closed 4 years ago

igatto commented 4 years ago

Let's say I have a pretty strict timeouts inside my database.yml file:

  connect_timeout: 5
  wait_timeout: 5
  read_timeout: 5
  write_timeout: 5
  interactive_timeout: 5
  timeout: 5

And after 5 seconds of being idle when Hutch is trying to process a new payload. I have this error:

ActiveRecord::StatementInvalid - Mysql2::Error::ConnectionError: MySQL server has gone away

How should I refresh connection to the database?

michaelklishin commented 4 years ago

This is a fantastic question for an ActiveRecord forum. Neither Hutch nor Bunny have any restrictions or opinion on this.

One way would be to handle this error and reconnect. The existence of this module suggests that modern ActiveRecord might have a way of handling connection failures for you but this is just a guess.