Google Cloud SQL & time outs

So, for a client an instance of eHour is running on Google Compute Engine and the database is provided by Google Cloud SQL. All nice and dandy except for the “Caused by: java.net.SocketException: Connection timed out” exceptions that pop  up in the log file a bit too often.

After some searching I found https://developers.google.com/cloud-sql/faq#connections, specifically saying:

In cloud-hosted environments, you should manage your database connections differently than managing them in a conventional, on-premises server environment. We recommend that you design your applications to handle occasional connection failures by implementing an error handling strategy like exponential backoff. For an example, see Exponential backoff in the Google Cloud Storage documentation.

Apparently even the database connection can fail by design, interesting…