IL-0330 incident.io · 2023-04-20 (published)database
Requests timed out for two weeks waiting on Go's database/sql connection pool, one for almost 20 seconds
incident.io's Go application talks to Postgres through the connection pool in the database/sql package, which caps how many parts of the application can use the database at once; when every connection is in use, an operation blocks until one is free. In early 2023 requests intermittently waited for a connection, one of them for almost 20 seconds, and timed out. Because the waits were spread across many requests and pools and the database load looked normal, the team first shipped quick fixes for whatever looked slow: policy violations were moved to a materialised view instead of loading policies and all their incidents on each request, new indices were added, and queries that filtered on unindexed columns after a join were rewritten to filter on an indexed column already in the join. When the timeouts returned, a one second lock timeout was added to all transactions, and Slack webhooks, which can arrive in large batches and had each triggered database queries inside the HTTP request, were forwarded to PubSub for asynchronous processing.
After yet another period of timeouts, the team added a measure of how long each operation held a database connection. Hooks in gorm, the ORM, also counted time spent waiting for the pool, so a middleware built on the ngrok/sqlmw package recorded the time around each query and transaction, counting a transaction as one hold so its statements were not counted twice, and added it to the log line and trace of each HTTP request and PubSub message. While checking that this counter worked, the team noticed an unnecessary transaction opened every time the application handled a Slack modal submission, the HTTP endpoint Slack calls when a user confirms the view opened by a slash command such as /inc. The transaction was removed from most modal submissions and kept explicitly on the code paths that needed transactional guarantees. Because the timeouts did not happen every day, it took a few days to confirm that this was the cause; four months later there had been no further database timeouts. No single slow operation was behind the problem: many short transactions, added together, caused it.
- Severity
- –
- Scope
- Intermittent timeouts on API requests and other operations that used the database, over a period of two weeks
- Users affected
- –
- Region
- –
- Time to detect
- –
- Time to resolve
- –
Symptoms
Over two weeks in early 2023, incident.io's Go application intermittently timed out on requests that used its Postgres database. A customer reported the problem, Sentry showed a burst of context canceled errors, and the first episode was over within a minute.
The Grafana API dashboard confirmed that some API requests had timed out. The trace of one failed HTTP request showed it had waited almost 20 seconds to get a connection from the client-side connection pool in Go's database/sql package; the wait appeared as a database.sql.ConnectionPoolWait span, which incident.io had added by patching database/sql. Grouping the stuck requests in Kibana showed that the waits were spread across many kinds of requests and many connection pools, not one pool, and neither Kibana nor Google Cloud Trace showed a pattern in the slow requests.
Nothing obvious had changed: no code change had altered database usage much, traffic had not jumped, and logs, traces and dashboards showed nothing alarming. Historical HTTP traffic and PubSub metrics looked ordinary, and Heroku's Postgres statistics showed normal load apart from some queries that had grown slower as the database grew. The team fixed those slow queries, but the timeouts came back within a couple of days. A one second lock timeout on every transaction broke nothing but brought the team no closer to the cause, and moving Slack event handling to asynchronous processing through PubSub was followed by another period of timeouts the next day. In those two weeks the team deployed 24 performance and observability changes.
Root cause
Root cause Software defect
- Trigger
- –
Detection
A customer report and a flurry of context canceled errors in Sentry; the on-call engineer opened an incident and checked the Grafana API dashboard. In the second episode an incident was opened automatically and the on-call engineer was pulled into it.
Remediation
- Moved the policy violations calculation to a materialised view
- Added database indices for slow queries
- Rewrote queries to filter on an indexed column already present in the join
- Added a one second lock timeout to all transactions
- Forwarded incoming Slack webhooks to PubSub and processed them asynchronously
- Added a middleware that logs how long each operation holds a database connection
- Removed the unnecessary transaction from most Slack modal submissions, keeping it only where needed
Action items
–
Lessons
The cause was not one slow operation but many short transactions that, added together, caused the problem. The investigation left incident.io with a way to filter logs and traces by how long each operation holds a database connection, and with real performance improvements. Separate databases for separate parts of the application would probably have made the cause easier to find, but would bring distributed transactions and less convenient development environments, a trade-off incident.io chose not to make for now.
Sources
Related cases
IL-0451Setting indexes INVISIBLE on Aurora MySQL 3.10 spiked CPU and ReadIOPS on all three readers but not on the writerDaangn · 2026same root cause · shared Database
IL-0313Decagon voice requests stalled for exactly 300 seconds behind self-managed PgBouncer and exhausted the SQLAlchemy poolDecagon · 2026same root cause · shared Database
IL-0281PostHog's Logs ClickHouse cluster silently deleted almost all its S3 data, losing US logs older than 3 daysPostHog · 2026same root cause · shared Database
IL-0310An Aurora PostgreSQL failover to an upsized reader reversed twice and backend writes failed in read-only transactionsHightouch · 2025same root cause · shared Database
IL-0150A latent race condition in DynamoDB's DNS automation left an empty DNS record for dynamodb.us-east-1.amazonaws.com, and the DynamoDB and EC2 launch failures that followed caused EKS, ECS and Fargate container launch failures and cluster scaling delays in us-east-1Amazon Web Services · 2025same root cause · shared Database
IL-0436A supremum lock left by ROLLBACK TO SAVEPOINT in a long transaction blocked inserts and filled Aurora MySQL connectionsfreee · 2025same root cause · shared Database
IL-0527OpenStreetMap.org made no replication diffs for 16 hours as PostgreSQL logical decoding failed on a memory alloc errorOpenStreetMap Foundation · 2025same root cause · shared Database
IL-0329A routine migration left PGAudit stuck holding Postgres locks, causing intermittent timeouts and a 2-minute outageincident.io · 2025same root cause · shared Database
IL-0347About 25% of Scaleway FR-PAR-1 hypervisors lost VPC connectivity when both VPC BGP route reflectors got stuckScaleway · 2024same root cause · shared Database
IL-0373Heroku Postgres Essential-tier databases in the EU region ran out of memory and refused connections, twice in four daysHeroku · 2024same root cause · shared Database
IL-0024Expensive cache-backed API calls and uncancelled database requests overloaded MongoDB and took the Hugging Face Hub down three timesHugging Face · 2024same root cause · shared Database
IL-0217Honeycomb's main MySQL database locked up under cache-miss reads and ran out of connections, a 68-minute total outageHoneycomb · 2023same root cause · shared Database
IL-0385GitHub MySQL read replicas hit a semaphore deadlock during a schema migration's table rename and kept crash-recoveringGitHub · 2021same root cause · shared Database
IL-0462Some MySQL pods on Shopify's GKE clusters took up to 30 minutes to start, slowing instance replacementShopify · 2021same root cause · shared Database
IL-0196Adding a second Redis replica and lowering memory limits in one RedisFailover change restarted the only Redis pod that held data, and Sentinel promoted the empty new replica, erasing the dataPalark · 2020same root cause · shared Database
IL-0486Figma's PostgreSQL 9 database on RDS slowed under high write IOPS and lock contention until the site was unavailableFigma · 2020same root cause · shared Database
IL-0241A database shard could not elect a new primary, and the Stripe API failed most requests in two periods on one dayStripe · 2019same root cause · shared Database
IL-0439Database access slowed after each block device and filesystem expansion because the Linux kernel dropped the page cacheCybozu · 2018same root cause · shared Database
IL-0388A Google Cloud live migration took a Discord Redis primary offline, and the failover broke API instances and then guildsDiscord · 2017same root cause · shared Database
IL-0454Baemin billing servers could not open new MariaDB connections at the start of a card-discount eventWoowa Brothers · 2016same root cause · shared Database
IL-0536Amazon SimpleDB in US East returned HTTP 500 to nearly all API calls for two hours after its nodes left the clusterAmazon Web Services · 2014same root cause · shared Database
IL-0485Dropbox went down when an OS upgrade script reinstalled active MySQL master-replica pairs and backup restores ran slowDropbox · 2014same root cause · shared Database
IL-0589Every Kickstarter MySQL replica on Amazon RDS stopped replicating on a duplicate-key error in the backings tableKickstarter · 2013same root cause · shared Database
IL-0303GitHub's MySQL master failed over to a node with a cold buffer pool during a schema migration and GitHub.com went downGitHub · 2012same root cause · shared Database
Check your cluster for this
For AI tools and scripts
- This case as JSON: https://incidentlib-api.benchlet.com/cases/IL-0330
- The cases most like it: https://incidentlib-api.benchlet.com/cases/IL-0330/similar
- MCP server (Streamable HTTP, no key):
https://incidentlib-mcp.benchlet.com/mcp
The API needs no key. The MCP server offers search_incidents, get_incident, list_incidents, get_topic and vocab; both are explained on API and MCP.