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): treat offline token_uri endpoint as non-retryable (#64841)

Tom Owers798cacf3bfcf
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.py
index 662fde389b57..a58c14b4777a 100644
--- a/posthog/temporal/data_imports/sources/bigquery/source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/source.py
@@ -117,6 +117,13 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# proxy). Authentication can't succeed until the key file is fixed, so retrying just
# hammers the endpoint and spams error tracking.
BIGQUERY_TOKEN_RESPONSE_ERROR: "We couldn't authenticate with BigQuery — Google's OAuth token endpoint returned an unexpected response. Please re-upload your service account key file and verify its token_uri.",
+ # A service-account key whose `token_uri` points at an ngrok tunnel that's offline:
+ # google-auth POSTs the token request and gets back ngrok's HTML error page instead of
+ # an OAuth JSON response, so it raises a `RefreshError` carrying that page. Google's real
+ # token endpoint is never fronted by ngrok, so this is a misconfigured `token_uri` — the
+ # user must fix their key file; retrying can't recover. Matched on ngrok's stable
+ # offline-endpoint code rather than the volatile tunnel subdomain in the page.
+ "ERR_NGROK_3200": "We couldn't authenticate with BigQuery — your service account key's token_uri points at an offline endpoint, not Google's OAuth token endpoint. Please re-upload your service account key file and verify its token_uri.",
# Raised as a `Forbidden` (403, reason `quotaExceeded`) when the customer's BigQuery
# project hits an administrator-configured custom cost control, e.g. "Custom quota
# exceeded: Your usage exceeded the custom quota for QueryUsagePerDay, which is set by
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 820584c1d916..f64700edeb12 100644
--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -438,6 +438,27 @@ def test_bigquery_malformed_table_id_is_non_retryable(observed_error):
assert all(non_retryable_errors[key] is not None for key in matching)
+ "observed_error",
+ [
+ # Offline ngrok tunnel — the subdomain varies but the stable error code does not.
+ "RefreshError: <!DOCTYPE html> <html> ... "
+ "<noscript>The endpoint tetrarchical-coercibly-norine.ngrok-free.dev is offline. (ERR_NGROK_3200)</noscript>",
+ # Different tunnel subdomain — the match must not rely on the volatile host part.
+ "RefreshError: <!DOCTYPE html> <html> ... "
+ "<noscript>The endpoint other-tunnel-name.ngrok-free.dev is offline. (ERR_NGROK_3200)</noscript>",
+ ],
+)
+def test_non_retryable_errors_match_offline_token_uri_endpoint(observed_error):
+ """A service account whose `token_uri` points at an offline ngrok tunnel makes google-auth
+ raise a `RefreshError` carrying ngrok's HTML error page — a misconfigured key the user must
+ fix, so the sync must be disabled rather than retried forever."""
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ matching = [key for key in non_retryable_errors if key in observed_error]
+ assert matching, "Offline token_uri endpoint error should be recognised as non-retryable"
+ assert all(non_retryable_errors[key] is not None for key in matching)
+
+
@pytest.mark.parametrize(
"transient_error",
[