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): recover EDBHANDLEREXITED pooler drop on all message variants (#64247)

Tom Owers296f01e50b2a
diff --git a/posthog/temporal/data_imports/sources/postgres/postgres.py b/posthog/temporal/data_imports/sources/postgres/postgres.py
index f95a1e4a8ebc..f6e79e0bb9a3 100644
--- a/posthog/temporal/data_imports/sources/postgres/postgres.py
+++ b/posthog/temporal/data_imports/sources/postgres/postgres.py
@@ -141,13 +141,15 @@ _CONNECTION_DROPPED_ERROR_SUBSTRINGS = (
# Supavisor (Supabase's connection pooler) doesn't surface a dropped upstream connection with a
# libpq/PgBouncer signature — it raises its own pooler-internal error as a generic psycopg
-# InternalError_ (SQLSTATE XX000) with the message "(EDBHANDLEREXITED) DbHandler exited. Check
-# logs for more information". The pooler's per-session DbHandler process exits when its backend
-# connection dies (idle cull, backend restart, failover), so it's the same transient class as the
-# libpq drops above and recovers on reconnect. Matched narrowly by the stable "DbHandler exited"
-# text — the surrounding "(EDBHANDLEREXITED)" code and trailing "Check logs..." vary and are
-# excluded — so genuine XX000 internal errors (data corruption, etc.) stay non-recoverable.
-_POOLER_CONNECTION_DROPPED_ERROR_SUBSTRINGS = ("dbhandler exited",)
+# InternalError_ (SQLSTATE XX000) carrying the "(EDBHANDLEREXITED)" code. The trailing message
+# varies — both "(EDBHANDLEREXITED) DbHandler exited. Check logs for more information" and
+# "(EDBHANDLEREXITED) connection to database closed. Check logs for more information" have been
+# observed for the same condition — but the EDBHANDLEREXITED code is the stable signal: the
+# pooler's per-session DbHandler process exited because its backend connection died (idle cull,
+# backend restart, failover). That's the same transient class as the libpq drops above and
+# recovers on reconnect, so match the code itself rather than any one message wording. Genuine
+# XX000 internal errors (data corruption, etc.) carry a different code and stay non-recoverable.
+_POOLER_CONNECTION_DROPPED_ERROR_SUBSTRINGS = ("edbhandlerexited",)
# Exception types that can carry a connection-dropped error. ProtocolViolation is
# PgBouncer's synthetic error packet; OperationalError is libpq detecting the dead
diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.py
index 5989a08505e4..c47b487883cd 100644
--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py
+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py
@@ -614,9 +614,13 @@ class TestIsConnectionDroppedError:
psycopg.errors.IdleInTransactionSessionTimeout(),
# Supavisor (Supabase's connection pooler) tears down a session whose backend connection
# died and surfaces it as a generic XX000 InternalError_ — a transient drop, not a libpq
- # signature, so it's matched on the pooler's own "DbHandler exited" text.
+ # signature, so it's matched on the pooler's own "(EDBHANDLEREXITED)" code. The trailing
+ # message wording varies for the same condition, so every observed variant must match.
psycopg.errors.InternalError_("(EDBHANDLEREXITED) DbHandler exited. Check logs for more information"),
psycopg.errors.InternalError_("(EDBHANDLEREXITED) DBHANDLER EXITED. Check logs for more information"),
+ psycopg.errors.InternalError_(
+ "(EDBHANDLEREXITED) connection to database closed. Check logs for more information"
+ ),
],
)
def test_connection_dropped_errors_are_detected(self, error):
@@ -637,7 +641,7 @@ class TestIsConnectionDroppedError:
ValueError("server conn crashed?"),
Exception("server conn crashed?"),
# A genuine XX000 internal error that isn't the Supavisor pooler drop must stay
- # non-recoverable — the InternalError_ match is scoped to the "DbHandler exited" text.
+ # non-recoverable — the InternalError_ match is scoped to the "(EDBHANDLEREXITED)" code.
psycopg.errors.InternalError_("XX000: internal error: something went wrong"),
],
)