IL-0313 Decagon · 2026-08-05 (published)databasegcp
Decagon voice requests stalled for exactly 300 seconds behind self-managed PgBouncer and exhausted the SQLAlchemy pool
Decagon sets the PostgreSQL application name to the current request path, and whenever the value changes Postgres sends it back to the client in a ParameterStatus packet. The stall needed three conditions: an application name longer than 41 bytes, which makes the ParameterStatus packet larger than 64 bytes; a query response of a size that makes that packet cross PgBouncer's 4096-byte read buffer; and both parts of the split packet in the same TLS record between Postgres and PgBouncer. The first two had existed for some time, and the migration to self-managed PgBouncer added the third. Because GCP's managed pooler also uses PgBouncer and the data path stayed the same, Decagon had expected a simple migration, and staging seemed to confirm it.
PgBouncer's read loop waits for epoll() to report a readable socket, copies the data into its read buffer and parses PostgreSQL messages. With TLS, SSL_read() drains a whole TLS record from the kernel socket into OpenSSL's buffer and returns only as many plaintext bytes as requested, keeping the rest inside OpenSSL. In one reproduction Postgres sent a single 4,118-byte TLS record, PgBouncer read 4,096 bytes, and an 86-byte ParameterStatus packet crossed the boundary: PgBouncer saw 70 bytes, decided it needed more data and went back to epoll() without checking SSL_pending(), while the remaining 16 bytes sat in OpenSSL and nothing woke the connection. The query stayed blocked in cursor.execute() until Postgres killed the session after 300 seconds, so its connection stayed checked out of SQLAlchemy's process-level QueuePool. A few such connections shrank the pool, and unrelated requests sharing it failed with pool exhaustion.
Decagon shortened the application name so the ParameterStatus packet stayed below PgBouncer's small-packet parsing threshold, which removed one condition and let the migration continue. Upstream, Decagon merged a small fix to PgBouncer's event loop that checks SSL_pending() before sleeping and keeps reading when OpenSSL already holds plaintext.
- Severity
- –
- Scope
- During the production canary, a small number of voice requests stalled mid-conversation for 300 seconds, and unrelated requests sharing the same connection pool failed with pool exhaustion
- Users affected
- –
- Region
- –
- Time to detect
- –
- Time to resolve
- –
Symptoms
During the first production canary of Decagon's move from GCP's managed connection pooler to self-managed PgBouncer, a small number of voice requests stalled mid-conversation and timed out after exactly 300 seconds. Other requests failed much earlier because the SQLAlchemy connection pool was exhausted.
Sentry showed a handful of "SSL connection has been closed unexpectedly" errors, and the pool failures read "sqlalchemy.exc.TimeoutError: QueuePool limit of size 2 overflow 20 reached, connection timed out, timeout 30.00". The SSL errors appeared only after PostgreSQL's idle-in-transaction session timeout ended the stalled sessions, so they looked like isolated connection failures with no link to the pool errors.
The pool error suggested the application had simply run out of database connections, but the other signals did not fit a capacity problem: Postgres query latency stayed at 1–3 milliseconds at p95, and PgBouncer's maxwait, the time clients wait for a server connection, stayed at zero. Comparing timelines showed that Postgres finished the affected queries in milliseconds while the application spans stayed open for exactly 300 seconds before returning the expected rows. The stalled queries kept their connections checked out of the QueuePool, and other requests timed out after 30 seconds waiting for those connections.
The stall was rare. Only two backend endpoints set an application name long enough to cause it, and only a small share of their query responses had the size that exposed the bug, so it never showed in staging.
Root cause
Root cause Software defect
- Trigger
- The move from GCP's managed connection pooler to self-managed PgBouncer enabled a different TLS path between PgBouncer and Postgres, which supplied the last of three conditions needed to expose the bug.
Detection
Sentry errors ("SSL connection has been closed unexpectedly") and SQLAlchemy connection-pool timeouts during the production canary, followed by a comparison of application spans with Postgres query timings.
Remediation
- Shortened the application name parameter so the ParameterStatus packet stayed below PgBouncer's small-packet parsing threshold
Action items
- Fix PgBouncer upstream so it checks SSL_pending() before going back to wait on epoll()
Lessons
Decagon's lesson is that an infrastructure migration does not only change one's own systems but can also expose latent bugs elsewhere in the stack: the move to self-managed PgBouncer supplied the last condition for a long-standing edge case involving SQLAlchemy, PgBouncer, OpenSSL and the PostgreSQL wire protocol.
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-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-0330Requests timed out for two weeks waiting on Go's database/sql connection pool, one for almost 20 secondsincident.io · 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-0313
- The cases most like it: https://incidentlib-api.benchlet.com/cases/IL-0313/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.