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(data-imports): classify app-db DNS blips in the postgres queue consumer as transient (#107773)

Tom Owersfd1dadad23df
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py
index 0962339a91f1..d0519225c486 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py
@@ -21,7 +21,6 @@ import structlog
from asgiref.sync import sync_to_async
from posthog.exceptions_capture import capture_exception
-from posthog.temporal.common.db_errors import is_transient_db_error
from products.warehouse_sources.backend.models.external_data_schema import (
SCHEMA_DELETED_JOB_ERROR,
@@ -75,6 +74,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.sync_lock import (
release_v3_pipeline_lock,
)
+from products.warehouse_sources.backend.temporal.data_imports.util import is_transient_internal_db_error
from products.warehouse_sources.backend.types import ExternalDataJobStatus
from products.warehouse_sources_queue.backend.models import SourceBatchStatus
@@ -334,7 +334,7 @@ class DeltaBatchConsumerAdapter:
)
except Exception as e:
# Leave the job for the reconcile sweep rather than crashing the consumer.
- if is_transient_db_error(e):
+ if is_transient_internal_db_error(e):
logger.warning(
"fail_run_job_status_update_app_db_not_ready",
job_id=batch.job_id,
@@ -587,7 +587,7 @@ class DeltaBatchConsumerAdapter:
error=ref.reason or "run failed (reconciled from queue)",
)
except Exception as e:
- if is_transient_db_error(e):
+ if is_transient_internal_db_error(e):
logger.warning(
"reconcile_job_status_update_app_db_not_ready",
job_id=ref.job_id,
@@ -677,7 +677,7 @@ class DeltaBatchConsumerAdapter:
error=STRANDED_RUN_ERROR,
)
except Exception as e:
- if is_transient_db_error(e):
+ if is_transient_internal_db_error(e):
logger.warning(
"stranded_run_job_status_update_app_db_not_ready",
job_id=ref.job_id,
@@ -772,7 +772,7 @@ class DeltaBatchConsumerAdapter:
job_dead = await self._is_job_dead(batch)
except Exception as e:
# Fail open: an app-DB hiccup must never wedge the loader.
- if is_transient_db_error(e):
+ if is_transient_internal_db_error(e):
logger.warning(
"job_status_check_app_db_not_ready", batch_id=batch.id, job_id=batch.job_id, error=str(e)
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
index 8b1c16540e1a..a2e739ed0c21 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
@@ -1646,8 +1646,18 @@ class TestFailRun:
mock_status.assert_called_once()
+ @pytest.mark.parametrize(
+ "error_message",
+ [
+ "server login has been failing, cached error: the database system is in recovery mode (server_login_retry)",
+ # The app DB's own host briefly stopping resolving — not a customer source, so
+ # this must not be treated like a permanently misconfigured host.
+ "[Errno -2] Name or service not known",
+ ],
+ ids=["pooler_login_retry_cooldown", "app_db_host_dns_blip"],
+ )
@pytest.mark.asyncio
- async def test_does_not_report_app_db_not_ready_error(self):
+ async def test_does_not_report_app_db_not_ready_error(self, error_message):
# Same self-healing app-DB refusal as TestReconcileFailedRuns, but hit while
# fail_run marks the job Failed directly rather than via the reconcile sweep.
consumer = _make_consumer()
@@ -1660,10 +1670,7 @@ class TestFailRun:
),
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer._update_job_status_to_failed",
- side_effect=DjangoOperationalError(
- "server login has been failing, cached error: the database system is in "
- "recovery mode (server_login_retry)"
- ),
+ side_effect=DjangoOperationalError(error_message),
),
patch(f"{consumer_module.__name__}.capture_exception") as mock_capture,
):
@@ -1868,11 +1875,22 @@ class TestShouldProcessBatch:
assert result is True
mock_queue_fail.assert_not_called()
+ @pytest.mark.parametrize(
+ "error_message",
+ [
+ "server login has been failing, cached error: the database system is in recovery mode (server_login_retry)",
+ # The app DB's own host briefly stopping resolving (infra moving under a
+ # long-lived worker) — not a customer source, so this must not be treated
+ # like a permanently misconfigured host.
+ "[Errno -2] Name or service not known",
+ ],
+ ids=["pooler_login_retry_cooldown", "app_db_host_dns_blip"],
+ )
@pytest.mark.asyncio
- async def test_status_check_does_not_report_app_db_not_ready_error(self):
- # Same fail-open behavior as above, but for the self-healing app-DB refusal this
- # was reported against: it must still fail open without paging error tracking,
- # since the app DB accepts connections again within seconds.
+ async def test_status_check_does_not_report_app_db_not_ready_error(self, error_message):
+ # Same fail-open behavior as above, but for self-healing app-DB refusals: these
+ # must still fail open without paging error tracking, since the app DB accepts
+ # connections again within seconds.
consumer = _make_consumer()
conn = consumer._poll_conn
assert conn is not None
@@ -1881,10 +1899,7 @@ class TestShouldProcessBatch:
with (
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer._get_job_status_and_error",
- side_effect=DjangoOperationalError(
- "server login has been failing, cached error: the database system is in "
- "recovery mode (server_login_retry)"
- ),
+ side_effect=DjangoOperationalError(error_message),
),
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.BatchQueue.fail_run",
@@ -2342,8 +2357,18 @@ class TestReconcileFailedRuns:
assert mock_mark.call_count == 2 # error on the first ref does not abort the sweep
+ @pytest.mark.parametrize(
+ "error_message",
+ [
+ "server login has been failing, cached error: the database system is in recovery mode (server_login_retry)",
+ # The app DB's own host briefly stopping resolving — not a customer source, so
+ # this must not be treated like a permanently misconfigured host.
+ "[Errno -2] Name or service not known",
+ ],
+ ids=["pooler_login_retry_cooldown", "app_db_host_dns_blip"],
+ )
@pytest.mark.asyncio
- async def test_does_not_report_app_db_not_ready_error(self):
+ async def test_does_not_report_app_db_not_ready_error(self, error_message):
# Reproduces the reported issue: the app DB (read via the Django ORM, not the queue
# DB) briefly refuses connections during a failover while the reconcile sweep is
# marking a job Failed. This self-heals within seconds and the sweep already retries
@@ -2379,10 +2404,7 @@ class TestReconcileFailedRuns:
),
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.mark_job_failed_if_not_terminal",
- side_effect=DjangoOperationalError(
- "server login has been failing, cached error: the database system is in "
- "recovery mode (server_login_retry)"
- ),
+ side_effect=DjangoOperationalError(error_message),
),
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.release_v3_pipeline_lock",
@@ -2393,8 +2415,18 @@ class TestReconcileFailedRuns:
mock_capture.assert_not_called()
+ @pytest.mark.parametrize(
+ "error_message",
+ [
+ "server login has been failing, cached error: the database system is in recovery mode (server_login_retry)",
+ # The app DB's own host briefly stopping resolving — not a customer source, so
+ # this must not be treated like a permanently misconfigured host.
+ "[Errno -2] Name or service not known",
+ ],
+ ids=["pooler_login_retry_cooldown", "app_db_host_dns_blip"],
+ )
@pytest.mark.asyncio
- async def test_stranded_run_sweep_does_not_report_app_db_not_ready_error(self):
+ async def test_stranded_run_sweep_does_not_report_app_db_not_ready_error(self, error_message):
# Same self-healing app-DB refusal, but hit by the stranded-run sweep the reconcile
# sweep runs after the main failed-runs pass, on the same mark_job_failed_if_not_terminal seam.
consumer = _make_consumer()
@@ -2440,10 +2472,7 @@ class TestReconcileFailedRuns:
),
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.mark_job_failed_if_not_terminal",
- side_effect=DjangoOperationalError(
- "server login has been failing, cached error: the database system is in "
- "recovery mode (server_login_retry)"
- ),
+ side_effect=DjangoOperationalError(error_message),
),
patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.release_v3_pipeline_lock",