:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(postgres): retry pgbouncer's query_wait_timeout as a transient pool error (#125643)
Tom Owerse5533d725354
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.pyindex 7f278b301e83..852c6b7af60e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py@@ -380,6 +380,14 @@ _CONNECTION_DROPPED_ERROR_SUBSTRINGS = (# retry must catch it. Match the stable prefix + reason and leave pgcat's non-transient reasons# (e.g. BadConfig) to surface."could not get connection from the pool - allserversdown",+ # PgBouncer's own pool-checkout timeout: a client already holds its PgBouncer-facing socket but+ # waits past `query_wait_timeout` for a backend to free up in transaction/statement-pooling mode.+ # PgBouncer reports this as a bare, SQLSTATE-less "query_wait_timeout" over a raw error packet+ # that doesn't follow the normal error-message framing, which psycopg surfaces as ProtocolViolation+ # rather than OperationalError. Same transient pool-capacity class as pgcat's AllServersDown and+ # Supavisor's ECHECKOUT* above — a slot frees the moment another transaction returns its backend —+ # so a fresh reconnect recovers.+ "query_wait_timeout",# psycopg's own message when `PQconnectStart` reports the connection BAD before the handshake# ever begins and libpq has no server-reported error text to attach (see# `psycopg.generators._connect` / `psycopg.pq.misc._clean_error_message`). Unlike every otherdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex 176e0767c87b..6fb37afbb5a6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -2789,6 +2789,12 @@ class TestIsConnectionDroppedError:# Supavisor XX000 InternalError_ codes above. Transient — a banned server rejoins on a# passing health check or once its ban expires — so the reconnect must catch it.psycopg.errors.SystemError("could not get connection from the pool - AllServersDown"),+ # PgBouncer's own pool-checkout timeout: the client waits past `query_wait_timeout` for a+ # backend to free up in transaction/statement-pooling mode. PgBouncer reports this as a+ # bare "query_wait_timeout" over a raw error packet, which psycopg surfaces as+ # ProtocolViolation rather than OperationalError. Same transient pool-capacity class as+ # the pgcat/Supavisor checkout failures above; the reconnect must catch it.+ psycopg.errors.ProtocolViolation("query_wait_timeout"),# psycopg's own message when `PQconnectStart` reports the connection BAD before the# handshake begins and libpq has no server-reported error text to attach — a purely# local pre-handshake failure (e.g. the worker briefly out of file descriptors), not a