: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): recognize read-replica timeout QueryTimeoutException at activity layer (#65352)
Tom Owers1db924e555a7
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.pyindex 8bd503058787..d0bf1df656db 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@@ -440,6 +440,15 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"max_standby_streaming_delay on the replica, enable hot_standby_feedback, or point the ""connection at the primary database, then re-enable the sync."),+ # Activity-layer twin of the `QueryTimeoutException` key above, for the read-replica path:+ # when a recovery conflict forces the offset-chunking fallback and a chunk then hits the+ # 10-minute statement_timeout, `get_rows` raises `QueryTimeoutException` with this message.+ # The class-name key only matches once Temporal wraps the failure; the activity-level check+ # sees the raw `str(e)`, which is the bare message with no class name. Without a message key+ # the timeout goes unrecognised there and the activity burns its full retry budget re-reading+ # from the start into the same conflicting, overloaded replica before the workflow gives up.+ # Match the stable leading phrase of our own crafted message.+ "Reading from your read replica timed out": None,"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.",# The source server itself ran out of memory (PostgreSQL SQLSTATE 53200, psycopg'sdiff --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 3326286afec2..2a43994510a2 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@@ -628,6 +628,26 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Exhausted recovery-conflict abort should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw activity-level message (what `_handle_import_error` sees via str(e)) — no class name.+ # Raised by get_rows when a recovery conflict forces offset chunking and a chunk then hits+ # the 10-minute statement timeout.+ "Reading from your read replica timed out: Postgres canceled the initial read with a "+ "recovery conflict, and the chunked fallback read still couldn't finish within the 10 "+ "minute statement timeout. Increase max_standby_streaming_delay or enable "+ "hot_standby_feedback on the replica, or sync from the primary database instead.",+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ "QueryTimeoutException: Reading from your read replica timed out: Postgres canceled the "+ "initial read with a recovery conflict",+ ],+ )+ def test_read_replica_timeout_query_timeout_is_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"Read-replica timeout error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[