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(snowflake): bound connection network_timeout so stalled requests fail fast (#67070)

Tom Owers0f3fb2c56d98
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/snowflake.py
index a44e6f86a440..001f42057ee7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/snowflake.py
@@ -81,6 +81,17 @@ _SNOWFLAKE_IDENTIFIER_QUOTER = AnsiIdentifierQuoter()
# Snowflake exposes one metadata schema per database; everything else is user data.
SNOWFLAKE_SYSTEM_SCHEMA = "INFORMATION_SCHEMA"
+# Bound the connector's per-request retry budget. `network_timeout` defaults to infinite, so a
+# stalled/half-open connection mid-request (peer or network drop) retries forever in the worker
+# thread. The sync activities are threaded and the heartbeater runs on a separate event-loop task,
+# so the stall isn't surfaced by a missed heartbeat — the activity just runs until Temporal's
+# `start_to_close_timeout` cancels the thread mid socket-read, surfacing a misleading
+# `WantReadError`/`CancelledError`. Bounding it turns the stall into a fast, retryable
+# `OperationalError` well before the activity is cancelled. It applies per request, so it never caps
+# a long-running streaming sync. Kept comfortably under the schema-discovery activity's 10-minute
+# `start_to_close_timeout` while leaving ample room for legitimate per-request round-trips and retries.
+_SNOWFLAKE_NETWORK_TIMEOUT_SECONDS = 300
+
def _split_display_name(display_name: str, default_schema: Optional[str]) -> tuple[Optional[str], str]:
"""Split a `schema.table` display name into `(schema, table)`.
@@ -262,6 +273,7 @@ class SnowflakeImplementation(
# `schema=""` would try `USE SCHEMA ""`, an invalid identifier, and fail at connect time.
schema=normalize_namespace(config.schema),
role=config.role,
+ network_timeout=_SNOWFLAKE_NETWORK_TIMEOUT_SECONDS,
**auth_connect_args,
) as connection:
yield connection
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index 74c48089f4bf..c2470c98a5e7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -17,6 +17,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import SnowflakeSourceConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.postgres import source_requires_ssl
from products.warehouse_sources.backend.temporal.data_imports.sources.snowflake.snowflake import (
+ _SNOWFLAKE_NETWORK_TIMEOUT_SECONDS,
SnowflakeImplementation,
_build_query,
_parse_clustering_key_leading_column,
@@ -338,6 +339,20 @@ class TestConnect:
pass
assert mock_connect.call_args.kwargs["schema"] == "SALES"
+ def test_bounds_network_timeout(self, impl):
+ # Without a bounded `network_timeout` the connector retries a stalled request forever, so the
+ # threaded sync activity hangs until Temporal cancels it mid socket-read (a noisy WantReadError
+ # / "Cancelled"). Keep a finite bound so the stall becomes a fast, retryable error instead.
+ with patch("snowflake.connector.connect") as mock_connect:
+ mock_connect.return_value.__enter__.return_value = MagicMock()
+ with impl.connect(_make_config()):
+ pass
+ network_timeout = mock_connect.call_args.kwargs["network_timeout"]
+ # A finite, positive bound is the invariant. `0` reads as infinite to the connector, so
+ # guard that explicitly — equality alone can't catch the constant regressing to `0`.
+ assert network_timeout == _SNOWFLAKE_NETWORK_TIMEOUT_SECONDS
+ assert network_timeout > 0
+
class TestSourceRequiresSsl:
def test_handles_config_without_ssh_tunnel(self):