: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(data-warehouse): classify pgbouncer login-retry errors as transient (#111822)
Tom Owers98fce8a24afc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.pyindex 0a4323ee6db9..369445ed877b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py@@ -2957,6 +2957,13 @@ class TestQueueDbRetry:(psycopg.errors.ConnectionTimeout("connection timeout expired"), True, True),(psycopg.errors.AdminShutdown("terminating connection due to administrator command"), True, True),(psycopg.errors.ProtocolViolation("query_wait_timeout"), True, True),+ (+ psycopg.errors.ProtocolViolation(+ "server login has been failing, cached error: connect failed (server_login_retry)"+ ),+ True,+ True,+ ),(psycopg.errors.DeadlockDetected("deadlock detected"), False, True),(psycopg.errors.ProtocolViolation("invalid message length"), False, False),(psycopg.OperationalError("relation permission denied"), False, False),diff --git a/products/warehouse_sources_queue/backend/core/batch_consumer.py b/products/warehouse_sources_queue/backend/core/batch_consumer.pyindex 882f905e71c1..2b41b969994e 100644--- a/products/warehouse_sources_queue/backend/core/batch_consumer.py+++ b/products/warehouse_sources_queue/backend/core/batch_consumer.py@@ -182,6 +182,21 @@ def _is_pooler_query_wait_timeout_error(error: BaseException) -> bool:return _POOLER_QUERY_WAIT_TIMEOUT_MARKER in str(error).lower()+# pgbouncer's server_login_retry cooldown: a backend connect attempt failed, so pgbouncer+# caches the failure and hands it to every client asking for a connection until the cooldown+# elapses and it retries the backend itself. Self-heals without our retry doing anything+# special, so it's transient by construction, not a symptom of the underlying cause. Same+# ProtocolViolation (SQLSTATE 08P01) shape as the query_wait_timeout marker above, so matched+# the same way. Mirrors posthog/temporal/common/db_errors.py's identical marker for the app DB.+_POOLER_LOGIN_RETRY_CACHED_ERROR_MARKER = "server login has been failing, cached error"+++def _is_pooler_login_retry_cached_error(error: BaseException) -> bool:+ if not isinstance(error, psycopg.errors.ProtocolViolation):+ return False+ return _POOLER_LOGIN_RETRY_CACHED_ERROR_MARKER in str(error).lower()++def _is_transient_queue_db_error(error: BaseException) -> bool:"""Whether `error` is the queue DB being briefly unavailable rather than a bug.@@ -195,6 +210,7 @@ def _is_transient_queue_db_error(error: BaseException) -> bool:or _is_admin_shutdown_error(error)or _is_connection_dropped_error(error)or _is_pooler_query_wait_timeout_error(error)+ or _is_pooler_login_retry_cached_error(error))