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 an exhausted HeadBucket 403 as transient (#111337)

Tom Owers25155b6d8d89
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py
index 479e212db437..92ef2d6baa03 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py
@@ -69,6 +69,16 @@ def is_transient_object_store_error(error: BaseException) -> bool:
made. Same transient-capacity class already recognized on the postgres connect path
(`_is_too_many_open_files_error`): a descriptor frees the moment another connection/client in
this worker closes, so it's fd pressure on our side, never an object-store or customer problem.
+
+ Deliberately does not cover `ensure_bucket_exists`'s own exhausted `HeadBucket` 403 retry (see
+ `_is_exhausted_head_bucket_forbidden` below) — that check only runs under `USE_LOCAL_SETUP`,
+ where the bucket credentials are operator-configured rather than our own IAM instance role, so an
+ exhausted retry can genuinely mean a broken local setup, not just a boot race. Callers that must
+ eventually give up and report a persistent failure (e.g. `repartition_table.py`'s
+ `_is_transient_infra_error`, which bounds retries via `MAX_REPARTITION_ATTEMPTS`) call this
+ function directly and so never see that shape as transient. Only the best-effort pre-extraction
+ probe (`is_transient_maintenance_error`, which has no such give-up budget to bypass and whose
+ failure is a silent no-op either way) folds it in.
"""
if isinstance(
error, TransientObjectStoreError | botocore.exceptions.NoCredentialsError | botocore.exceptions.ConnectionError
@@ -85,6 +95,23 @@ def is_transient_object_store_error(error: BaseException) -> bool:
)
+def _is_exhausted_head_bucket_forbidden(error: BaseException) -> bool:
+ """True for the `ClientError` `ensure_bucket_exists` raises once its own `HeadBucket` 403 retries
+ are exhausted (see its `_HEAD_BUCKET_MAX_ATTEMPTS` loop).
+
+ The response carries no error body to tell a credential-bootstrap race (a local/self-hosted
+ object store still starting up) apart from a genuine, persistent denial — same ambiguity as the
+ sibling `HeadObject` case `_is_retryable_purge_error` documents. Unlike that case, an exhausted
+ retry here isn't folded into `is_transient_object_store_error`: see that function's docstring for
+ why only a caller with no give-up budget to bypass should treat this shape as transient.
+ """
+ return (
+ isinstance(error, botocore.exceptions.ClientError)
+ and error.operation_name == "HeadBucket"
+ and error.response.get("Error", {}).get("Code") == "403"
+ )
+
+
# `optimize.compact` plans its rewrite against the file list at the start of its scan, then reads
# those files. A concurrent maintenance pass on the same table (e.g. a Temporal activity attempt that
# heartbeat-timed-out but keeps running as a zombie — see this package's README on the equivalent
@@ -193,6 +220,11 @@ def is_transient_maintenance_error(error: BaseException) -> bool:
(SQLSTATE 25006) for that, which psycopg classifies under `InternalError` rather than
`OperationalError`, so it needs its own check — a bare `InternalError` isinstance check would be
too broad and swallow real corruption errors (e.g. `DataCorrupted`) that share the same base class.
+
+ Also folds in an exhausted `ensure_bucket_exists` `HeadBucket` 403 (see
+ `_is_exhausted_head_bucket_forbidden`) — safe here specifically because this function only backs
+ the best-effort pre-extraction probe, which has no retry budget to bypass and already no-ops
+ silently on any failure, transient or not.
"""
if isinstance(error, OperationalError | InterfaceError):
return True
@@ -200,4 +232,6 @@ def is_transient_maintenance_error(error: BaseException) -> bool:
return True
if _is_too_many_open_files_error(error):
return True
+ if _is_exhausted_head_bucket_forbidden(error):
+ return True
return is_transient_object_store_error(error) or is_transient_delta_maintenance_error(error)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py
index b5725b49293f..717f6e2cf42f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py
@@ -94,6 +94,16 @@ class TestIsTransientObjectStoreError:
# further up the stack that catches broadly and re-runs this classifier on the caught
# exception sees the wrapper, not the original — it must still read as transient.
("already_wrapped_transient_error", TransientObjectStoreError("Please reduce your request rate"), True),
+ (
+ # An exhausted `ensure_bucket_exists` HeadBucket 403 retry is deliberately NOT folded
+ # in here: under `USE_LOCAL_SETUP` the credentials are operator-configured, so this
+ # shape can mean a genuinely broken local setup, not just a boot race. Only
+ # `is_transient_maintenance_error` (which has no retry budget to bypass) treats it as
+ # transient — see TestIsTransientMaintenanceError.
+ "exhausted_head_bucket_forbidden_not_matched_here",
+ botocore.exceptions.ClientError({"Error": {"Code": "403"}}, "HeadBucket"),
+ False,
+ ),
]
)
def test_classifies_transient_errors(self, _name: str, error: Exception, expected: bool):
@@ -237,6 +247,30 @@ class TestIsTransientMaintenanceError:
),
True,
),
+ (
+ # `ensure_bucket_exists` already retries this exact shape (a bodyless HeadBucket 403,
+ # same ambiguity as the HeadObject case in TestIsTransientObjectStoreError) before
+ # giving up — an exhausted retry is the tail of that same local/self-hosted
+ # object-store bootstrap race. Only safe to fold in here: this function backs the
+ # best-effort pre-extraction probe, which has no retry budget to bypass.
+ "exhausted_head_bucket_forbidden",
+ botocore.exceptions.ClientError({"Error": {"Code": "403"}}, "HeadBucket"),
+ True,
+ ),
+ (
+ # A 403 from some other S3 operation isn't the bodyless-response ambiguity HeadBucket
+ # has — must not be swept up just because it shares the error code.
+ "other_operation_403_not_matched",
+ botocore.exceptions.ClientError({"Error": {"Code": "403"}}, "PutObject"),
+ False,
+ ),
+ (
+ # A HeadBucket failure with a different code (e.g. a real AccessDenied that does
+ # carry a body) isn't the bootstrap race either.
+ "head_bucket_non_403_not_matched",
+ botocore.exceptions.ClientError({"Error": {"Code": "AccessDenied"}}, "HeadBucket"),
+ False,
+ ),
# Other InternalError subtypes (e.g. real corruption) must not be swept up by the
# ReadOnlySqlTransaction check just because they share the same Django exception class.
(