: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(warehouse-sources): retry postgres syncs on supavisor's instance-wide connection cap (#108859)
Tom Owers397706255cc4
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 bdc4c30128fb..887afc7dd00a 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@@ -384,18 +384,24 @@ _POOLER_CONNECTION_DROPPED_ERROR_SUBSTRINGS = (# and "too many connections for role" once a role's own CONNECTION LIMIT is hit. Supabase's# Supavisor session-mode pooler reports its own variant when every client slot it exposes is in use# ("(EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size:-# <n>"). All of these are transient capacity conditions on the customer's database or pooler — a-# slot frees the moment another connection closes (or a session ends) — so a fresh connect after a-# short backoff usually succeeds. Retried in-process on the read/sync connect path (see+# <n>"). Supavisor also has an instance-wide sibling: when the pooler's total client-facing+# connection count (across every tenant it serves, not just this one) hits its own configured cap,+# it refuses new connects with "FATAL: (EMAXCONN) max client connections reached, limit: <n>" — the+# same transient capacity class, since a slot frees the moment any tenant's connection closes. All of+# these are transient capacity conditions on the customer's database or pooler — a slot frees the+# moment another connection closes (or a session ends) — so a fresh connect after a short backoff+# usually succeeds. Retried in-process on the read/sync connect path (see# `_is_dropped_or_connect_timeout` / `_connect_with_dropped_retry`); kept retryable and intentionally-# NOT added to `get_non_retryable_errors` (see source.py). The Supavisor match is on the stable-# "max clients reached in session mode" phrase, excluding the volatile pool_size and the-# "(EMAXCONNSESSION)" code (mirrors the `PostgresErrors` validation mapping in source.py).+# NOT added to `get_non_retryable_errors` (see source.py). The Supavisor matches are on the stable+# "max clients reached in session mode" / "max client connections reached" phrases, excluding the+# volatile pool_size/limit numbers and the "(EMAXCONNSESSION)" / "(EMAXCONN)" codes (mirrors the+# `PostgresErrors` validation mapping in source.py)._CONNECTION_LIMIT_ERROR_SUBSTRINGS = ("sorry, too many clients already","remaining connection slots are reserved","too many connections for role","max clients reached in session mode",+ "max client connections reached",)# Exception types that can carry a connection-dropped error. ProtocolViolation isdiff --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 52ead070b831..c79ce509f0b6 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@@ -2616,6 +2616,12 @@ class TestIsConnectionLimitError:'connection failed: connection to server at "10.0.0.1", port 5432 failed: '"FATAL: (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15"),+ # Supavisor's instance-wide sibling of EMAXCONNSESSION: the pooler's total client-facing+ # connection count (across every tenant) hit its own cap, not just this tenant's pool.+ psycopg.OperationalError(+ 'connection failed: connection to server at "10.0.0.1", port 6543 failed: '+ "FATAL: (EMAXCONN) max client connections reached, limit: 200"+ ),# A pooler (PgBouncer-style) that caches an upstream login failure reveals the limit on# the first query as a ProtocolViolation, not an OperationalError — it must still be# recognised so the discovery retry recovers instead of surfacing it as captured noise.@@ -2627,6 +2633,7 @@ class TestIsConnectionLimitError:)def test_connection_limit_errors_are_detected(self, error):assert _is_connection_limit_error(error) is True+ assert _is_dropped_or_connect_timeout(error) is True@pytest.mark.parametrize("error",