: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): disable idle-in-transaction timeout on CDC stream connection (#66781)
Tom Owers03f6954e2425
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.pyindex 3c10fd92e994..f725246ae492 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py@@ -92,11 +92,15 @@ class PgCDCStreamReader:user=self._params.user,password=self._params.password,require_ssl=self._params.require_ssl,- # Server-side ceiling (30m) so a stalled WAL decode can't hang the streaming- # connection indefinitely. Bounds a single peek; the caller's soft deadline- # bounds the whole run. Dropped if the source sits behind a pooler that rejects- # the libpq `options` parameter (CDC sources never do).- options="-c statement_timeout=1800000",+ # statement_timeout (30m) is a server-side ceiling so a stalled WAL decode can't+ # hang the streaming connection indefinitely; it bounds a single peek, the caller's+ # soft deadline bounds the whole run. idle_in_transaction_session_timeout=0 stops the+ # source culling our backend (SQLSTATE 25P03) while the named cursor's transaction+ # sits idle between yields as the caller flushes to S3 and advances the slot —+ # statement_timeout doesn't apply there because no statement is running. Both are+ # dropped if the source sits behind a pooler that rejects the libpq `options`+ # parameter (CDC sources never do).+ options="-c statement_timeout=1800000 -c idle_in_transaction_session_timeout=0",),logger,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_stream_reader.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_stream_reader.pyindex 71908b16a044..4ed470b6ff2e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_stream_reader.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_stream_reader.py@@ -109,7 +109,7 @@ class TestPgCDCStreamReaderConnect:class TestPgCDCStreamReaderConnectOptions:- def test_connect_sets_statement_timeout(self, params):+ def test_connect_sets_streaming_timeouts(self, params):connect = mock.MagicMock(return_value=mock.MagicMock())reader = PgCDCStreamReader(params)with patch(@@ -118,8 +118,12 @@ class TestPgCDCStreamReaderConnectOptions:):reader.connect()+ options = connect.call_args.kwargs["options"]# A stalled server-side WAL decode can't hang the streaming connection indefinitely.- assert "statement_timeout=1800000" in connect.call_args.kwargs["options"]+ assert "statement_timeout=1800000" in options+ # The named cursor holds a transaction open while the caller flushes between yields, so the+ # source must not cull the backend (SQLSTATE 25P03) for sitting idle in that transaction.+ assert "idle_in_transaction_session_timeout=0" in optionsclass TestPgCDCStreamReaderReadChanges: