Skip to content

: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.

fix(postgres): stop retrying a pooler auth-failure circuit breaker (#88318)

Tom Owersd3630eed20a2
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.py
index 547ad536bf28..6eb435dbf64e 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
@@ -255,9 +255,12 @@ _CONNECTION_DROPPED_ERROR_SUBSTRINGS = (
# carrying "(ECIRCUITBREAKER) failed to retrieve database credentials after multiple attempts,
# new connections are temporarily blocked". Same class as EAUTHQUERY above — the pooler's own
# bookkeeping failing, not a rejection of the client's credentials — and the breaker resets once
- # the fetch succeeds again, so a fresh connect after backoff typically recovers. Match the
- # stable code, distinct from genuine credential-rejection wordings.
- "(ecircuitbreaker)",
+ # the fetch succeeds again, so a fresh connect after backoff typically recovers. Match the full
+ # "failed to retrieve database credentials" wording, NOT the bare "(ECIRCUITBREAKER)" code —
+ # Supavisor reuses the same code for a different condition ("too many authentication failures",
+ # tripped by repeated bad credentials rather than pooler bookkeeping), which must stay
+ # non-retryable and is matched separately in source.py's `get_non_retryable_errors`.
+ "(ecircuitbreaker) failed to retrieve database credentials",
# pgcat (a Rust Postgres pooler) refuses to hand out a backend when every server in the pool is
# currently banned/down — a failed health check bans a server and pgcat auto-unbans it after
# `ban_time` — reporting it as SQLSTATE 58000 ("could not get connection from the pool -
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
index 61972a6086d2..4d9045f33347 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
@@ -145,6 +145,14 @@ PostgresErrors = {
"(for example Supabase's transaction pooler) also require a pooler-specific username such "
"as postgres.<project-ref>. Check your credentials and try again."
),
+ # Supavisor's own circuit breaker for repeated authentication failures against a tenant.
+ # `get_non_retryable_errors` already handles this on the streaming path; map it here too so
+ # validation returns an actionable message instead of the generic fallback.
+ "too many authentication failures": (
+ "Your database's connection pooler has temporarily blocked new connections after repeated "
+ 'authentication failures ("too many authentication failures"). This usually means the '
+ "username or password is wrong. Check your credentials and try again."
+ ),
"could not translate host name": "Could not connect to the host",
# libpq prefixes a DNS-resolution failure with "could not translate host name ..." (matched
# above), but the same getaddrinfo failure also surfaces as the raw socket wording with no such
@@ -413,6 +421,21 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"through PAM (for example against the system password database or LDAP), and it "
"rejected the username or password. Check your credentials, then re-enable the sync."
),
+ # Supavisor trips its own circuit breaker after repeated authentication failures against
+ # a tenant and temporarily refuses new connects, reporting "FATAL: (ECIRCUITBREAKER) too
+ # many authentication failures, new connections are temporarily blocked". Distinct from
+ # the pooler-bookkeeping "(ECIRCUITBREAKER) failed to retrieve database credentials"
+ # variant kept retryable in postgres.py's `_CONNECTION_DROPPED_ERROR_SUBSTRINGS` — this one
+ # is tripped by the credentials themselves being rejected repeatedly, so it's the same
+ # deterministic class as "password authentication failed" and retrying with the same
+ # credentials just re-trips the breaker. Match the stable message, excluding the volatile
+ # host/port the raw driver text prefixes it with.
+ "too many authentication failures": (
+ "Your database's connection pooler has temporarily blocked new connections after "
+ 'repeated authentication failures ("too many authentication failures"). This usually '
+ "means the configured username or password is wrong. Check your credentials, then "
+ "re-enable the sync."
+ ),
"could not translate host name": _DNS_RESOLUTION_ERROR,
"timeout expired connection to server at": None,
"password authentication failed for user": _INVALID_CREDENTIALS_ERROR,
diff --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.py
index 4f971abf6a37..b5d8d283aba3 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
@@ -714,6 +714,40 @@ class TestPostgresSourceNonRetryableErrors:
assert friendly, "PAM authentication failure should surface an actionable message"
assert "credentials" in friendly[0]
+ def test_circuit_breaker_too_many_auth_failures_is_non_retryable(self, source):
+ # Supavisor's "(ECIRCUITBREAKER)" code also covers a distinct, transient pooler-bookkeeping
+ # condition ("failed to retrieve database credentials", see postgres.py's
+ # `_CONNECTION_DROPPED_ERROR_SUBSTRINGS`) — confirm that variant does NOT trip this key, so
+ # the two "(ECIRCUITBREAKER)" wordings can't be confused for each other.
+ non_retryable = source.get_non_retryable_errors()
+ pooler_bookkeeping_msg = (
+ 'connection failed: connection to server at "10.0.0.1", port 5432 failed: '
+ "FATAL: (ECIRCUITBREAKER) failed to retrieve database credentials after multiple "
+ "attempts, new connections are temporarily blocked"
+ )
+ assert not any(pattern in pooler_bookkeeping_msg for pattern in non_retryable), (
+ "the transient pooler-bookkeeping ECIRCUITBREAKER wording must stay retryable"
+ )
+
+ auth_failure_msg = (
+ 'connection failed: connection to server at "18.176.230.146", port 5432 failed: '
+ "FATAL: (ECIRCUITBREAKER) too many authentication failures, new connections are "
+ "temporarily blocked"
+ )
+ assert "too many authentication failures" in non_retryable
+ assert any(pattern in auth_failure_msg for pattern in non_retryable)
+
+ def test_circuit_breaker_too_many_auth_failures_returns_friendly_message(self, source):
+ non_retryable = source.get_non_retryable_errors()
+ error_msg = (
+ 'connection failed: connection to server at "18.176.230.146", port 5432 failed: '
+ "FATAL: (ECIRCUITBREAKER) too many authentication failures, new connections are "
+ "temporarily blocked"
+ )
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, "the auth-failure circuit breaker should surface an actionable message"
+ assert "credentials" in friendly[0]
+
def test_supavisor_enotfound_tenant_user_uses_new_key(self, source):
# The older tenant/user patterns don't cover the newer "(ENOTFOUND) tenant/user" wording,
# so confirm it's specifically the new key that recognises this message.
@@ -1889,6 +1923,16 @@ class TestIsConnectionDroppedError:
# permanent rejection — only the "no error details available" variant (a purely local,
# pre-handshake failure) is transient, so the match must not broaden to the bare prefix.
psycopg.OperationalError("connection is bad: FATAL: password authentication failed"),
+ # Supavisor reuses the "(ECIRCUITBREAKER)" code for a distinct, permanent condition: its
+ # own circuit breaker tripped by repeated authentication failures against a tenant, not
+ # the transient pooler-bookkeeping variant ("failed to retrieve database credentials")
+ # kept retryable above. Broadening the match to the bare code would wrongly retry a
+ # deterministic credential rejection — see `get_non_retryable_errors` in source.py.
+ psycopg.OperationalError(
+ 'connection failed: connection to server at "18.176.230.146", port 5432 failed: '
+ "FATAL: (ECIRCUITBREAKER) too many authentication failures, new connections are "
+ "temporarily blocked"
+ ),
],
)
def test_unrelated_errors_are_not_detected(self, error):
@@ -3714,6 +3758,19 @@ class TestValidateCredentialsErrorMapping:
"connection pooler), enable your provider's IPv4 add-on, or add PostHog's IP addresses to your "
"firewall allowlist, then try again.",
),
+ # Supavisor trips its own circuit breaker after repeated authentication failures against
+ # a tenant. Distinct from the "(ECIRCUITBREAKER) failed to retrieve database credentials"
+ # pooler-bookkeeping wording (kept retryable elsewhere) — this one means the credentials
+ # themselves keep being rejected, so it must surface actionable credential guidance
+ # instead of falling through to the generic fallback message below.
+ (
+ 'connection failed: connection to server at "18.176.230.146", port 5432 failed: '
+ "FATAL: (ECIRCUITBREAKER) too many authentication failures, new connections are "
+ "temporarily blocked",
+ "Your database's connection pooler has temporarily blocked new connections after "
+ 'repeated authentication failures ("too many authentication failures"). This usually '
+ "means the username or password is wrong. Check your credentials and try again.",
+ ),
# Unmapped errors fall back to the generic message.
(
"some brand new failure",