Database connection keep alive

Symptom

I often see error message such as Communications link failure for saved questions. However after refresh the page, everything went back to normal. If I check the page again after a while (e.g. an hour), the error is back again.

A reasonable assumption is that I have a Metabase instance connecting to MySQL via a proxy, which drops idle connections.

Proposal

Perhaps we can use a connection pool and/or some kind of keep alive query for unstable connections?

We do actually use connection pools to maintain open connections to frequently accessed databases, but it’s entirely possible that since you are using a proxy that the connection is getting dropped by the proxy event though Metabase thinks it’s open.

I’d love to hear more about your configuration so that I could try replicating it and seeing if we can setup an easy work around.

Ok, I’ve tried two configurations.

option (A)
metabase (on EC2) connects directly to MySQL instance (RDS which disconnects clients idling for 2+ minutes)
option (B)
metabase (on EC2) connects to MySQL via haproxy (which redispatch request upon error)

Is there a reason why in option A the RDS instance disconnects clients after 2 minutes?

We use option A ourselves and we have over a dozen MB instances that we help maintain which are all using that same model and i’ve never had the problem you are describing.

We have hundreds of idle clients created by employee whom open new connection just like browser tabs.

Anyway, can you either issue ping-pong query when idling or check for viability before you use a connection from the pool?

Hi hden,

Yes, we have put in a little code to address that situation as seen here … https://github.com/metabase/metabase/pull/1940/files

This will be out in our next release (0.15.0) which goes out next week.

1 Like

I’m working under a database that is dropping connections after a minute. (Don’t ask, I’ve been down this road already.) Is there any way to adjust that keep alive’s interval?