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(bigquery): lift gRPC message-size limit on storage read channel (#64174)

Tom Owers9c62c2971ff8
diff --git a/posthog/temporal/data_imports/sources/bigquery/bigquery.py b/posthog/temporal/data_imports/sources/bigquery/bigquery.py
index 302d46f33fa1..35bed62d7185 100644
--- a/posthog/temporal/data_imports/sources/bigquery/bigquery.py
+++ b/posthog/temporal/data_imports/sources/bigquery/bigquery.py
@@ -206,7 +206,22 @@ def bigquery_storage_read_client(
# via `create_channel(credentials=...)`. This routes the Storage Read API's
# create_read_session (unary) + read_rows (server-streaming) RPCs through our
# logging / metrics / sample-capture pipeline.
- channel = BigQueryReadGrpcTransport.create_channel(host=BIGQUERY_STORAGE_HOST, credentials=credentials)
+ #
+ # `read_rows` streams Arrow record batches whose ReadRowsResponse messages
+ # routinely exceed gRPC's default 4 MiB client receive limit (wide rows or large
+ # string columns such as GeoJSON push a single message past it). When the
+ # transport builds its own channel it sets both message-length limits to -1
+ # (unlimited); because we supply the channel ourselves that default is skipped,
+ # so we must replicate it here. Without it large pages fail with RESOURCE_EXHAUSTED
+ # "Received message larger than max" and the sync can never make progress.
+ channel = BigQueryReadGrpcTransport.create_channel(
+ host=BIGQUERY_STORAGE_HOST,
+ credentials=credentials,
+ options=[
+ ("grpc.max_send_message_length", -1),
+ ("grpc.max_receive_message_length", -1),
+ ],
+ )
tracked_channel = make_tracked_channel(channel, host=BIGQUERY_STORAGE_HOST)
transport = BigQueryReadGrpcTransport(channel=tracked_channel)
diff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
index 48975864d0df..72acb910bbc9 100644
--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -6,6 +6,7 @@ from dateutil import parser
from google.api_core.exceptions import BadRequest, Forbidden, NotFound, PermissionDenied
from posthog.temporal.data_imports.pipelines.pipeline.typings import SourceInputs
+from posthog.temporal.data_imports.sources.bigquery import bigquery as bq_module
from posthog.temporal.data_imports.sources.bigquery.bigquery import (
BIGQUERY_TOKEN_RESPONSE_ERROR,
BigQueryImplementation,
@@ -616,3 +617,30 @@ def test_bigquery_dataset_not_found_in_location_is_non_retryable(location):
non_retryable_errors = BigQuerySource().get_non_retryable_errors()
assert any(pattern in error_msg for pattern in non_retryable_errors)
+
+
+def test_bigquery_storage_read_client_disables_grpc_message_size_limit():
+ """Regression: the Storage Read API streams Arrow ReadRowsResponse messages that can
+ exceed gRPC's default 4 MiB client receive limit (wide rows / large string columns like
+ GeoJSON), which surfaced as `_MultiThreadedRendezvous` RESOURCE_EXHAUSTED "Received
+ message larger than max". Because we build the channel ourselves, we must pass the same
+ unlimited message-length options the transport sets on its own default channel."""
+ with (
+ mock.patch.object(bq_module.service_account.Credentials, "from_service_account_info", return_value=mock.Mock()),
+ mock.patch.object(bq_module, "make_tracked_channel", return_value=mock.Mock()),
+ mock.patch.object(bq_module, "BigQueryReadGrpcTransport") as mock_transport_cls,
+ mock.patch.object(bq_module.bigquery_storage, "BigQueryReadClient"),
+ ):
+ with bq_module.bigquery_storage_read_client(
+ project_id="project-id",
+ private_key="private-key",
+ private_key_id="private-key-id",
+ client_email="client-email",
+ token_uri="token-uri",
+ ):
+ pass
+
+ mock_transport_cls.create_channel.assert_called_once()
+ options = dict(mock_transport_cls.create_channel.call_args.kwargs["options"])
+ assert options["grpc.max_receive_message_length"] == -1
+ assert options["grpc.max_send_message_length"] == -1