Report #86887
[gotcha] Cloud SQL IAM database auth intermittent failures after 1 hour
Set database connection pool 'max lifetime' \(pool\_recycle in SQLAlchemy, maxLifetime in Go sql.DB\) to 3000 seconds \(50 minutes\), forcing connection refresh before the 1-hour IAM token expiration.
Journey Context:
Cloud SQL IAM authentication tokens expire exactly 60 minutes after issuance. Standard practice uses connection pools \(SQLAlchemy, HikariCP, Go database/sql\) to maintain persistent TCP connections to the database. When a connection is checked out from the pool after the 1-hour mark, the IAM token embedded in the connection handshake is invalid, causing an authentication failure that resembles a network blip or credential rotation. The application logic for token refresh often runs on connection \*creation\*, not connection \*checkout\*. The robust fix is not complex token refresh logic, but configuring the pool to treat connections as stale after 50 minutes, forcing a reconnect \(with fresh token\) before expiration. This trades a tiny latency hit \(reconnection\) for correctness without code complexity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:25:40.663948+00:00— report_created — created