: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-imports): recognize psycopg's dead-socket message as a transient db error (#83876)
Tom Owersd1aa2742c383
diff --git a/posthog/temporal/common/db_errors.py b/posthog/temporal/common/db_errors.pyindex 0e70c1ebc988..a9a027d9d2ba 100644--- a/posthog/temporal/common/db_errors.py+++ b/posthog/temporal/common/db_errors.py@@ -17,6 +17,12 @@ _TRANSIENT_DB_ERROR_MARKERS = (# (default 15s) 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."server login has been failing, cached error",+ # psycopg's own message when libpq finds the backend socket already gone (raised as a+ # ProtocolViolation, SQLSTATE 08P01, which the class-based check above doesn't cover since+ # 08P01 also covers genuine protocol bugs). Same dead-socket condition as the "closed+ # unexpectedly" marker above, just detected client-side instead of reported by the server.+ # Reaches us standalone too, not only wrapped in the cached-login message above.+ "server conn crashed",)# SQLSTATE class 57P (operator intervention): the server is shutting down or restarting anddiff --git a/posthog/temporal/common/test_db_errors.py b/posthog/temporal/common/test_db_errors.pyindex 1eff874602f0..97ef1d26d582 100644--- a/posthog/temporal/common/test_db_errors.py+++ b/posthog/temporal/common/test_db_errors.py@@ -24,6 +24,9 @@ class _WithSqlstate(Exception):OperationalError("server login has been failing, cached error: server conn crashed? (server_login_retry)"),True,),+ # The dead-socket message on its own, without pgbouncer's cached-login wrapper — the case+ # the marker above doesn't cover.+ (OperationalError("server conn crashed?"), True),(OperationalError("connection failed: FATAL: password authentication failed for user"), False),(OperationalError("no such database"), False),],@@ -37,6 +40,7 @@ def test_is_transient_db_error_by_message(error: BaseException, expected: bool)[("57P03", True), # cannot_connect_now (server starting up/shutting down)("3D000", False), # invalid_catalog_name — persistent misconfiguration+ ("08P01", False), # protocol_violation — shared with genuine protocol bugs, so message-only],)def test_is_transient_db_error_by_sqlstate(sqlstate: str, expected: bool) -> None: