: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(postgres): treat exhausted recovery-conflict retries as non-retryable (#63031)
Tom Owers7e59045ced53
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex 4bf8627e019b..4c352fe6ca0b 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -188,6 +188,22 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"SSLRequiredError": None,"SSL/TLS connection is required": None,"Could not establish session to SSH gateway": None,+ # `offset_chunking` retries a Postgres standby recovery conflict ("canceling statement+ # due to conflict with recovery") 30 times in-process with backoff + chunk-size+ # reduction before raising this. The conflict comes from the customer's read replica+ # applying WAL that removes row versions our long-running read still needs+ # (max_standby_streaming_delay exceeded). Once those in-process retries are exhausted the+ # condition is sustained, not a transient blip — retrying the whole activity just+ # re-reads from offset 0 into the same wall, so stop and surface an actionable message.+ # Matched substring excludes the volatile retry count and is distinct from the+ # connection-dropped abort ("successive connection-dropped errors"), which stays retryable.+ "successive SerializationFailure errors. Aborting.": (+ "PostHog repeatedly hit Postgres recovery conflicts while reading from your read replica "+ '("canceling statement due to conflict with recovery"). This happens when the replica must '+ "apply changes from the primary that remove rows the sync is still reading. Increase "+ "max_standby_streaming_delay on the replica, enable hot_standby_feedback, or point the "+ "connection at the primary database, then re-enable the sync."+ ),"DiskFull": "Source database ran out of disk space. Free up disk space on your database server or add an index on your incremental field to reduce temp file usage.","No space left on device": "Source database ran out of disk space. Free up disk space on your database server or add an index on your incremental field to reduce temp file usage.",# Raised when a Postgres numeric value cannot be represented in any Delta-compatiblediff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex 9b6ce1d1a057..bbb4ac136628 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -171,6 +171,33 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Widened integer column error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ "Hit 30 successive SerializationFailure errors. Aborting.",+ "Exception: Hit 30 successive SerializationFailure errors. Aborting.",+ ],+ )+ def test_exhausted_recovery_conflict_retries_are_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"Exhausted recovery-conflict error should be non-retryable: {error_msg}"++ @pytest.mark.parametrize(+ "error_msg",+ [+ # A single recovery conflict is retried in-process; on its own it must stay retryable.+ "canceling statement due to conflict with recovery",+ "could not serialize access due to conflict with recovery",+ # The connection-dropped abort is a separate, genuinely transient condition.+ "Hit 10 successive connection-dropped errors. Aborting.",+ ],+ )+ def test_recovery_conflict_related_transients_stay_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert not is_non_retryable, f"Transient error should remain retryable: {error_msg}"+class TestIsConnectionDroppedError:@pytest.mark.parametrize(