Skip to content

Azure: retry transient authentication failures on the remaining object-storage call sites - #112875

Closed
arsenmuk wants to merge 1 commit into
masterfrom
arsenmuk/az-retry-callsites
Closed

arsenmuk wants to merge 1 commit into
masterfrom
arsenmuk/az-retry-callsites

Conversation

@arsenmuk

@arsenmuk arsenmuk commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Series: #112871 → #112875 (this), #112872, #112873, #112874, #112876

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Retry a transient Azure AuthenticationException (credential/token-acquisition failure, e.g. during the managed-identity/RBAC propagation window) on object-storage call sites that previously had no retry at all: blob existence/metadata/size probes, single and batch deletes, the post-upload verification, the container existence check, and ADLS Gen2 writes. Previously a single transient credential failure at any of these points failed the whole query or background job.


Follow-up to #112871, which handles the HTTP half of the problem: the Azure SDK RetryPolicy now retries a transient 403 for every client (retry_options.StatusCodes.insert(Forbidden) in AzureBlobStorageCommon.cpp).

What the SDK cannot retry is Azure::Core::Credentials::AuthenticationException: it is thrown by the credential/token layer around the transport, so the retry policy — which only sees HTTP responses and TransportException — never observes it. The read/download/write buffer loops already absorb it via their catch (...) retry, but these call sites had no retry of any kind:

  • AzureObjectStorage::exists and getObjectMetadata / getObjectMetadataIfExists — one-shot GetProperties()
  • AzureObjectStorage::removeObjectImpl (blob and ADLS) and the batch SubmitBatch
  • ReadBufferFromAzureBlobStorage::tryGetFileSize / getRemoteFileMetadata
  • WriteBufferFromAzureBlobStorage::finalizeImpl post-upload verification — the upload already succeeded, a transient credential failure must not turn a good write into a failure
  • containerExists in the client factory — the first request many flows issue
  • WriteBufferFromAzureDataLakeStorage::runWithRetries — retried HTTP errors but let AuthenticationException escape on the first attempt

A single transient credential failure at any of them surfaced as a query/job failure.

Changes:

  • New retryAzureOnAuthError() (src/IO/AzureBlobStorage/retryAzureOnAuthError.h): bounded exponential backoff around AuthenticationException only. HTTP-status retries deliberately stay in the SDK retry policy (Fix transient Azure errors misreported as broken data parts #112871), so retry layers don't stack multiplicatively. getBlobPropertiesWithRetry() lives in the same header for the GetProperties() sites.
  • Route the call sites above through it; widen their Azure::Storage::StorageException catches to the base Azure::Core::RequestFailedException (a behavior-preserving superset; NotFound handling unchanged).
  • ADLS Gen2 runWithRetries additionally retries AuthenticationException within the same budget (shared give-up/backoff tail for both failure kinds).
  • readBigAt: guard against a null body stream in the download response (mirrors the existing guard in initialize()).
  • Tests (test_azure_403_handling): a one-shot injected AuthenticationException on the direct metadata path (no ClickHouse-level retry loop anywhere) must be absorbed — this test fails without this PR; a permanent one must still fail with the real auth error after the bounded budget.

Compared to the previous revision of this PR: all 403/HTTP retrying has been removed from the helper. After #112871 that is the SDK retry policy's job; doing it here as well would stack a second retry loop on top of the SDK's (up to 3 × 11 attempts on a permanent 403). This PR is now strictly about the auth exception the SDK cannot see. The per-object batch re-issue loop is gone for the same reason (an RBAC 403/auth failure is per-principal, i.e. all-or-nothing across a batch; batch-level retry covers it).

Not covered by tests: the ADLS Gen2 write path (azurite cannot emulate ADLS/OneLake endpoints).

Stacked on #112871 (branch base); to be merged after it.

@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b4f2c5c]

Summary: ✅


AI Review

Summary

This PR adds bounded retries for transient Azure AuthenticationException failures on several one-shot metadata, delete, and ADLS write paths. The direction is right, but the current patch still leaves unprotected auth-failure exits in adjacent container-create and copy flows, misses one batch-delete retry surface that the PR explicitly claims to cover, and leaves one new single-delete failure mode unlogged, so I would not approve it yet.

Findings

❌ Blockers

  • [src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp:315-316] Hardening stops at containerExists, but the same client-factory path still issues a one-shot CreateBlobContainer at src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp:365. If the container is absent and that request hits the same transient credential/RBAC propagation failure, writable Azure object-storage initialization still aborts on the first attempt.
    Suggested fix: pass the configured retry budget into getContainerClient and wrap CreateBlobContainer in retryAzureOnAuthError.
  • [src/IO/AzureBlobStorage/copyAzureBlobStorageFile.cpp:165, 216, 322, 420, 431] The Azure copy helper still lets transient AuthenticationException escape from Upload, StageBlock, CommitBlockList, CopyFromUri, StartCopyFromUri, and the copy-status polling path. AzureObjectStorage::copyObject and backup copy flows therefore still fail on the first credential glitch even though this PR claims to cover the remaining object-storage call sites.
    Suggested fix: route the native-copy and upload SDK calls through retryAzureOnAuthError, or add one outer retry helper around each copy strategy.
  • [src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp:483-516] Batch delete now retries only the top-level SubmitBatch, but per-object failures from deferred_response.GetResponse are still treated as final. Because the code already models batch responses as per-object deferred subresponses, a transient retryable 403 in one subresponse still gets logged and rethrown as a hard delete failure instead of being retried, so the PR does not fully fix the batch-delete contract it describes.
    Suggested fix: keep a per-object retry path for retryable subresponses, or re-issue the affected objects through the single-delete/auth-retry path before final logging.

⚠️ Majors

  • [src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp:365-372] retryAzureOnAuthError can now rethrow AuthenticationException from single-object deletes after the retry budget is exhausted, but removeObjectImpl only catches RequestFailedException. That means the new auth-failure path exits before either blob_storage_log->addEvent(... Delete ...) call, so failed deletes are no longer recorded in BlobStorageLog.
    Suggested fix: add an AuthenticationException or shared catch (...) path that logs the delete attempt before rethrowing, matching the batch-delete handling below.
  • [src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp:315-316] containerExists still hard-codes 3 retries while the rest of the PR uses settings->max_single_download_retries, which defaults to 4 and can be overridden per endpoint. A transient auth failure that clears on the fourth attempt still aborts initialization here even though the later one-shot probes would succeed.
    Suggested fix: thread the same configurable retry budget into this helper instead of keeping a separate constant.
Tests
  • ⚠️ [tests/integration/test_azure_403_handling/test.py:141-201] The new regression coverage proves only the direct GetProperties/exists auth path. There is still no focused failpoint test for a delete caller or for the auto-create-container path, so the new delete/create behavior can regress again without CI signal.
  • ⚠️ There is still no focused auth-failure coverage for the Azure copy helper, even though copyAzureBlobStorageFile remains the shared implementation for AzureObjectStorage::copyObject and backup copy flows.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: protect the remaining auth-failure paths in container creation and Azure copy, finish the batch-delete/single-delete behavior so retryable failures are either retried or at least logged consistently, and add the smallest focused regression coverage for delete/create (or narrow the PR contract if those paths are intentionally out of scope).

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.10% +0.10%

Changed lines: Changed C/C++ lines covered: 61/107 (57.01%) · Uncovered code

Full report · Diff report

/// A transient per-object 403/auth (RBAC-propagation window): re-issue this single delete
/// under the bounded retry policy before recording a failure.
if (isRetryableAzureException(e))
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This per-object batch fallback still misses the transient 403 path. isRetryableAzureException(e) here uses the default may_be_provisioning_access = false, so a Forbidden subresponse never reaches the single-object retry path and is logged as a hard delete failure instead.

Please use the same 403/auth retry policy here as the single-object delete path.

@arsenmuk
arsenmuk force-pushed the arsenmuk/az-retry-callsites branch from b236e30 to 13a0e90 Compare August 2, 2026 08:56
@arsenmuk
arsenmuk changed the base branch from master to arsenmuk/az-transient-not-broken-part August 2, 2026 08:57
/// retryable RequestFailedException (isRetryableAzureException) and a credential AuthenticationException
/// with bounded exponential backoff, then rethrow. Shared by the GetProperties, delete and copy callers.
template <typename Func>
auto retryAzureOperation(Func && func, size_t max_retries, const String & path, const LoggerPtr & log)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retryAzureOperation is now the shared correctness point for the new one-shot delete paths, and getBlobPropertiesWithRetry builds on it for exists, metadata reads, and post-upload verification. The only Azure failpoint regression test in tree still exercises merge/read paths (tests/integration/test_azure_403_handling/test.py), so these newly-routed call sites can regress again without any CI signal, which is exactly what happened in the earlier revision of this PR.

Please add focused failpoint integration coverage for at least one GetProperties caller and one delete caller under azure_inject_forbidden_response / azure_inject_auth_failure.

@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 99/176 (56.25%) · Uncovered code

Full report · Diff report

@arsenmuk
arsenmuk force-pushed the arsenmuk/az-retry-callsites branch from 13a0e90 to c7d6b8c Compare August 4, 2026 08:56
@arsenmuk arsenmuk changed the title Azure: retry transient 403/auth on the remaining object-storage call sites Azure: retry transient authentication failures on the remaining object-storage call sites Aug 4, 2026
@arsenmuk
arsenmuk force-pushed the arsenmuk/az-retry-callsites branch from c7d6b8c to a32a18b Compare August 5, 2026 09:49
@SmitaRKulkarni SmitaRKulkarni self-assigned this Aug 10, 2026
@arsenmuk
arsenmuk marked this pull request as ready for review August 11, 2026 14:54
Base automatically changed from arsenmuk/az-transient-not-broken-part to master August 12, 2026 17:18
@arsenmuk
arsenmuk force-pushed the arsenmuk/az-retry-callsites branch from a32a18b to 75fcc6d Compare August 12, 2026 18:01
client.GetProperties();
/// No RequestSettings are available at client-factory time; mirror the default retry count.
retryAzureOnAuthError([&] { return client.GetProperties(); },
/*max_retries*/ 3, "containerExists", getLogger("AzureBlobStorageCommon"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containerExists() is still using a hard-coded retry budget of 3, while every other one-shot call site in this PR uses settings->max_single_download_retries (which defaults to azure_max_single_read_retries = 4 and can be overridden per endpoint).

That means a transient AuthenticationException that clears on the 4th attempt still aborts client/disk initialization here even though the later GetProperties() / exists() probes this PR wraps would have succeeded. Since the PR explicitly claims to harden the container-existence check too, this path needs the same configurable budget instead of a separate constant.

@arsenmuk
arsenmuk force-pushed the arsenmuk/az-retry-callsites branch from 75fcc6d to 314b1d5 Compare August 12, 2026 19:08
namespace DB
{

/// A credential AuthenticationException is thrown by the token layer around the transport, so the SDK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retryAzureOnAuthError is introduced as the shared fix for one-shot Azure calls, but AzureObjectStorage::copyObject still goes through copyAzureBlobStorageFile (AzureObjectStorage.cpp:616-646). Inside that helper, the native-copy path (CopyFromUri / StartCopyFromUri) and the upload path (Upload, StageBlock, CommitBlockList) only catch RequestFailedException / StorageException and have no outer ClickHouse retry loop (copyAzureBlobStorageFile.cpp:165-233, 291-339, 395-459).

A transient credential-layer AuthenticationException therefore still aborts blob copies and backup copy flows on the first attempt, which violates the PR's "remaining object-storage call sites" contract. This helper needs to be wired into copyAzureBlobStorageFile too, or the PR contract/tests need to be narrowed to exclude copy paths.

@arsenmuk
arsenmuk force-pushed the arsenmuk/az-retry-callsites branch from 314b1d5 to b4f2c5c Compare August 12, 2026 20:36
client.GetProperties();
/// No RequestSettings are available at client-factory time; mirror the default retry count.
retryAzureOnAuthError([&] { return client.GetProperties(); },
/*max_retries*/ 3, "containerExists", getLogger("AzureBlobStorageCommon"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containerExists is now retried, but the sibling create path in the same factory flow is still one-shot:

service_client->CreateBlobContainer(params.endpoint.container_name)

If the container is absent and that request hits the same transient AuthenticationException / RBAC-propagation window, writable Azure object-storage initialization still fails on the first attempt. This PR is already touching the client-factory probe path, so the create step needs the same auth-retry hardening and budget instead of leaving new-container initialization uncovered.

Comment on lines +365 to +372
retryAzureOnAuthError([&] { buildDataLakeFileClient(path)->Delete(); },
settings.get()->max_single_download_retries, path, log);
success = true;
}
else
{
auto delete_info = client_ptr->GetBlobClient(path).Delete();
auto delete_info = retryAzureOnAuthError([&] { return client_ptr->GetBlobClient(path).Delete(); },
settings.get()->max_single_download_retries, path, log);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retryAzureOnAuthError can now rethrow AuthenticationException from this single-object delete path after the retry budget is exhausted, but the surrounding handler only catches RequestFailedException.

In that case the function exits before either of the blob_storage_log->addEvent(... Delete ...) calls, so the failed delete leaves no delete record at all on the new auth-retry path. The batch delete path just below already added a broad catch for exactly this reason; single-object deletes need the same logging-before-rethrow treatment (either with an explicit AuthenticationException catch or a shared catch (...) path).

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b4f2c5ce6 with master 405e218ff (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 692.09 MiB 689.10 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

10 object files changed (+104.86 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/clickhouse_common_io.dir/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/Azu… 402.88 KiB 425.21 KiB +22.33 KiB (+5.54%)
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureObjectStorage.… 402.88 KiB 425.21 KiB +22.33 KiB (+5.54%)
src/CMakeFiles/dbms.dir/Disks/IO/WriteBufferFromAzureBlobStorage.cpp.o 197.50 KiB 217.48 KiB +19.98 KiB (+10.12%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

13 translation units recompiled, 50 s compile time in total, 13 of them have a recent master baseline.

Job report

{
return func();
}
catch (const Azure::Core::Credentials::AuthenticationException & e)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not clear why we want to retry AuthenticationException ?
We have a function isRetryableAzureException, AuthenticationException is not one of them as this is not usually retryable, but please correct me if I am wrong

@clickhouse-gh clickhouse-gh Bot added the comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@arsenmuk

Copy link
Copy Markdown
Member Author

closing as not confirmed

@arsenmuk arsenmuk closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants