Cloud SQL connections dropped during maintenance or failover (server closed the connection)

Connections reset when Cloud SQL restarts for maintenance, a flag change or a high-availability failover.

Exact message you may see Cloud SQL maintenance connection resetserver closed the connection unexpectedly Cloud SQL failoverLost connection to MySQL server during query Cloud SQL maintenanceCloud SQL failover connections droppedterminating connection due to administrator command Cloud SQL
Seen on: Google Cloud PostgreSQL MySQL

Meaning

Expect brief downtime. Set a maintenance window, use HA, make clients retry with exponential backoff, validate pooled connections (pool_pre_ping, testOnBorrow) and keep short transactions. Re-resolve the instance after failover.

Common causes

  • Maintenance restart
  • HA failover
  • Flag change requiring restart
  • Stale pooled connections
  • No retry logic in the app

⚡ Quick fix

  1. Add retry/backoff and pool validation
  2. Set a maintenance window
  3. Use HA and the Auth Proxy/connector with reconnect

Detailed fix by platform

Python

  1. engine = create_engine(URL, pool_pre_ping=True, pool_recycle=1800)

How to diagnose

  1. Window — Known?
  2. Retry — Implemented?
  3. Pool — Validated?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

Auth Proxy — Cloud SQL Auth Proxy: failed to connect — IAM permission, API or IAM DB authentication problem (Google Cloud / Firebase)Auth ProxyCloud SQL: failed to connect to instance — Cloud SQL: failed to connect to `host=PROJECT:REGION:INSTANCE user=app database=db`: dial error (timeout) / Cloud SQL Auth Proxy: failed to connect to instance (Google Cloud / Firebase)Cloud SQL: failed to …Cloud SQL: too many connections — Cloud SQL: FATAL: remaining connection slots are reserved / MySQL: ERROR 1040 (08004): Too many connections (Google Cloud / Firebase)Cloud SQL: too many c…connection closed — server closed the connection unexpectedly — This probably means the server terminated abnormally before or while processing the request. (PostgreSQL)connection closedconnections — Realtime Database: 100 simultaneous connections limit on the Spark plan (new connections refused) (Google Cloud / Firebase)connectionsdatabase flags — Cloud SQL: invalid database flag value / instance fails to restart after a flag change (Google Cloud / Firebase)database flagsORA-00018 — ORA-00018: maximum number of sessions exceeded (SQL)ORA-00018ORA-00020 — ORA-00020: maximum number of processes (150) exceeded (SQL)ORA-00020maintenan…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.