Skip to content

Fix transient Azure errors misreported as broken data parts - #112871

Merged
arsenmuk merged 2 commits into
masterfrom
arsenmuk/az-transient-not-broken-part
Aug 12, 2026
Merged

arsenmuk merged 2 commits into
masterfrom
arsenmuk/az-transient-not-broken-part

Conversation

@arsenmuk

@arsenmuk arsenmuk commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

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

Problem. Transient Azure errors — a 403 (Forbidden), a credential AuthenticationException, and connect timeouts (surfaced as a synthetic 408) — were previously classified as non-retryable, which caused healthy data parts to be flagged as corrupt: POTENTIALLY_BROKEN_DATA_PART (code 740). Due to Azure RBAC propagation lag, these 403s are possible within minutes after service provisioning. They are not always caught by IDisk::checkAccess(), because that startup probe and the later data requests can be served by different Azure storage frontends holding different (stale) RBAC caches.

Fix. Treat 403/408 as retryable and throw a real TransportException for connect timeouts (instead of fabricating a 408), so the read path retries in-budget and a transient failure is never attributed to data corruption.

Changes.

  • IO/AzureBlobStorage/isRetryableAzureException: 403 + 408 retryable; drop the may_be_provisioning_access arg.
  • IO/AzureBlobStorage/PocoHTTPClient: throw Azure::Core::Http::TransportException on Poco::TimeoutException instead of a synthetic 408.
  • Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon: add 403 to the Azure SDK's retryable status codes — its default set omits it — so call sites without a ClickHouse-level retry loop are covered too.
  • Storages/MergeTree/checkDataPart (isRetryableException): treat AuthenticationException as retryable.
  • Common/FailPoint + tests/integration/test_azure_403_handling: failpoints and regression tests for transient vs permanent 403 / auth / timeout, plus a non-retryable error as a negative control.

Scope note. isRetryableAzureException no longer takes may_be_provisioning_access, so 403 is retryable at every call site, including writes; previously it was retryable only for IDisk::checkAccess() (#86419). Budgets stay bounded, so a permanent 403 still fails — now after the full budget (~18s on a read) instead of immediately. This also fixes the read half of checkAccess, which had no 403 tolerance at all. @tavplubix @alesapin — asking you to confirm this widening, as owners of the 403 gate and of the Poco HTTP client respectively.

Supersedes #111179 (same 408 fix), closed in favour of this — thanks @qiuyanjun888.

Closes #106298, #110724.

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 into CHANGELOG.md):

Fixed a transient Azure Blob Storage error on the read or merge path — an RBAC permission-propagation 403 Forbidden, a credential authentication failure, or a connect timeout surfaced as 408 — being misclassified as non-retryable and reported as POTENTIALLY_BROKEN_DATA_PART (Code 740), raising a false critical alert for a healthy part. These transient failures are now treated as retryable, and a genuinely persistent one surfaces as a plain Azure error instead of a phantom broken data part.

Version info

  • Merged into: 26.8.1.1265-master (included in 26.8 and later)
  • Backported to: 26.7.23.6

@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [88ea678]

Summary: ✅


AI Review

Summary

This PR reclassifies transient Azure 403, credential-authentication, and connect-timeout failures as retryable across the Azure transport, the MergeTree broken-part decision, and the affected regression tests. I read the current diff and prior review threads, traced the unchanged Azure read/write callers that share the retry helper, and did not find a remaining correctness or coverage gap that warrants a new review comment.

Final Verdict

✅ No blocking issues found.

LLVM Coverage Report

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

Changed lines: Changed C/C++ lines covered: 71/76 (93.42%) · Uncovered code

Full report · Diff report

@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: 40/51 (78.43%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

No arm_release build profile data for commit 88ea678 - the build was skipped, reused from cache, or predates profile upload.

@arsenmuk
arsenmuk marked this pull request as ready for review August 4, 2026 08:15
arsenmuk added a commit that referenced this pull request Aug 4, 2026
The base branch (arsenmuk/az-transient-not-broken-part, #112871) rewrote the
403/auth/timeout failpoints and the integration test after this PR was cut, so
merge it in and re-express the batch-delete test against the new conventions
(clean_state fixture, azure_inject_forbidden_response, azure_policy).

Address the two review comments on the batch-delete change:
- removeObjectsBatchIfExists now preserves the real Azure HTTP status in the
  batch-failure blob_storage_log Delete events (catch StorageException ->
  e.StatusCode), matching the per-object path; -1 is kept only for non-Azure
  failures (e.g. a credential AuthenticationException).
- The test asserts one failed Delete event per object, scoped to the dropped
  table's own blobs and to error_code = 403, instead of a global count() > 0.
arsenmuk added a commit that referenced this pull request Aug 4, 2026
The SDK RetryPolicy retries transient HTTP errors (including 403 after #112871)
but never sees Azure::Core::Credentials::AuthenticationException: it is thrown by
the credential layer around the transport. Retry it with bounded backoff at the
call sites that have no ClickHouse-level retry loop: existence/metadata/size
probes, single and batch deletes, the post-upload verification, the container
existence check, and ADLS Gen2 writes. HTTP-status retries deliberately stay in
the SDK retry policy so the two retry layers do not stack multiplicatively.
arsenmuk added a commit that referenced this pull request Aug 4, 2026
…-checkdatapart-rethrow

Resolve the moved base (the #112871 test suite was rewritten). Re-express the CHECK TABLE regression in the new suite as a plain-MergeTree test pinning the StorageMergeTree::checkDataNext caller, and fix the transposed name/message args in checkDataPart's retryable-error log line.
@arsenmuk
arsenmuk force-pushed the arsenmuk/az-transient-not-broken-part branch from 77e50f7 to f9d6177 Compare August 5, 2026 09:25
nickitat and others added 2 commits August 11, 2026 17:31
Previously `isRetryableAzureException` only treated HTTP 403 as
retryable when `may_be_provisioning_access=true`, which was only
set by `IDisk::checkAccessImpl` for the initial startup access
check. As a result, after a credential or role change, the brief
permission-propagation window caused in-flight SELECTs to fail.
Worse, `MergeTreeSequentialSource::generate`'s `catch (...)` invoked
`reportBrokenPart`, and `StorageSharedMergeTree::reportBrokenPart`'s
`catch (...)` reclassified the Azure exception as
`POTENTIALLY_BROKEN_DATA_PART`, which triggers loud alerting via
`ForcedCriticalErrorsLogger` even though the underlying part is fine.

Treat 403 as retryable in all callers. A genuinely permanent 403
still surfaces: in-buffer retries are bounded, and the final failure
is reported as a plain Azure error rather than a phantom broken
part. The `is_initial_access_check` flag is retained for its other
job (bumping `max_unexpected_write_error_retries` 3x at startup).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@arsenmuk
arsenmuk force-pushed the arsenmuk/az-transient-not-broken-part branch from f9d6177 to 88ea678 Compare August 11, 2026 16:31
return response;

/// Throw TransportException (retryable) for a timeout instead of a synthetic 408 that read as a broken part.
throw Azure::Core::Http::TransportException(getCurrentExceptionMessageAndPattern(true).text);

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.

I see that logic here is changed from
return to throw.
What stands behind this change?
From the code for S3 I see that return might be retried in sdk, but throw is not retried in sdk, exception goes to the clickhouse read buffer code.

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.

Do I understand it correct, that you make 403/408 errors retryable for isRetryableException in src/Storages/MergeTree/checkDataPart.cpp and in src/Disks/IO/WriteBufferFromAzureBlobStorage.cpp
but it would be not retriable in the SDK?

@CheSema CheSema Aug 12, 2026 •

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.

If I'm right, then you would not get a time on retries with fallbacks on such case, the query will fail fast, but the part would not be marked as broken.

BTW: The retries in the read buffer do not give you the right retries. Read buffer retries strange cases which we were not able to handle in the right palace back then, or the cases when SDK behaves wrong. There is a few retries count max_unexpected_write_error_retries=4.

Here I do not like that there is an inconsistency: it is written here and there that this error is retryable but it is retryable not anywhere.
You actually ended up in the solution when you made errors not retryable and not falty in the same time. Before this PR all not retryable errors were falty.
With this PR: all retryable errors are not faulty. Some not retryable errors are not falty also. The rest not retryable errors are faulty. Faulty errors are the errors which triggers a part to be broken.
But you did not write that classification to the code. That leads as to the state when we have retryable errors without retries.

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.

@groeneai check my conclusion here.
And answer the question:
How would 403/408 errors be retried in this PR? Who retry them, how, how much?

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.

I checked the Azure SDK, and this one does retry the throw. I'm wrong here. This error would be just retryable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for the questions. We just discussed offline a bit, and agreed on your latest conclusion - leaving it as is here, as the error will be retried via exception

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@CheSema Measured on this branch, azure disk, default settings.

403 after this PR. Two nested layers, neither of which covered 403 before:

  • The SDK RetryPolicy. Its default StatusCodes is {408, 500, 502, 503, 504} (azure-core/.../policies/policy.hpp:133), so 403 was excluded; this PR inserts it (AzureBlobStorageCommon.cpp:404). Budget azure_sdk_max_retries=10: 11 attempts, 10ms doubling capped at 1000ms, about 4.3s.
  • The read loop at ReadBufferFromAzureBlobStorage.cpp:137, azure_max_single_read_retries=4, backoff 100/200/400ms.

They nest rather than overlap, because PocoAzureHTTPClient::Send makes one attempt and leaves retrying to the pipeline (PocoHTTPClient.cpp:143). So a permanent 403 on a read becomes up to 44 HTTP requests over roughly 14-23s (jitter 0.8-1.3). On master that same 403 fails on the first request, since isRetryableAzureException returns true only under may_be_provisioning_access, and the reader's catch then calls reportBroken() (MergeTreeReaderWide.cpp:76). So it is not fail-fast as your second comment supposed; the cost is latency, not missing retries.

408. Already in the SDK default set. The PR replaces the synthetic 408 with a TransportException, which RetryPolicy catches explicitly (retry_policy.cpp:157) on the same budget. That agrees with your correction.

Your conclusion. I agree on the substance: the taxonomy is three-valued and written down nowhere. checkDataPart.h:19 declares isRetryableException with no comment, and 20 call sites across 10 files consume it.

Your "retryable without retries" case does still hold for one class, the one this PR adds: Azure::Core::Credentials::AuthenticationException. It derives from std::exception, not RequestFailedException (credentials.hpp:137), so isRetryableAzureException never sees it, and RetryPolicy catches only TransportException, so the SDK does not retry it either, even though the bearer-token policy that throws it runs inside the retry loop (pipeline.hpp:124, then :128). It is retried only where a ClickHouse loop has a catch-all, meaning the read and write buffers. AzureObjectStorage::exists, getObjectMetadata and listObjects have none, so there it is classified retryable and retried zero times.

Your last comment. Poco::Net::NetException derives from Poco::IOException, so both reach the catch-all at PocoHTTPClient.cpp:515 and become a synthetic 500 (:525). 500 is retryable at both layers, so the retries are right; the loss is diagnostic, since connection-refused becomes indistinguishable from a server-side 500. S3 keeps them apart, mapping each to NETWORK_CONNECTION (S3/PocoHTTPClient.cpp:757-770).

One note on the description: I found no thrower of POTENTIALLY_BROKEN_DATA_PART (740) in master. It occurs only at ErrorCodes.cpp:622 and in Exception::isErrorCodeImportant (Exception.cpp:302). The master outcome I could verify for these errors is reportBroken() queueing the part for check, not a 740 reaching the client.

Adjacent from my side: #114180 covers the not-found (404) class on the part-load path, which this PR does not touch.

/// Throw TransportException (retryable) for a timeout instead of a synthetic 408 that read as a broken part.
throw Azure::Core::Http::TransportException(getCurrentExceptionMessageAndPattern(true).text);
}
catch (...)

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.

here also could be:
Poco::Net::NetException
Poco::IOException
Poco::TimeoutException -- you handle it, ok
const NetException
Here they are substituded with InternalServerError.
S3 considered them as retriable network errors.

@CheSema CheSema Aug 12, 2026 •

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.

But I understand that you might consider it out of scope for this PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll add this as a follow-up. Thank you!

@arsenmuk
arsenmuk added this pull request to the merge queue Aug 12, 2026
Merged via the queue into master with commit 2e330af Aug 12, 2026
354 of 355 checks passed
@arsenmuk
arsenmuk deleted the arsenmuk/az-transient-not-broken-part branch August 12, 2026 17:18
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Aug 24, 2026
…rors

makeRequestInternalImpl caught client-side transport failures only via the
terminal catch(...), turning them into a synthetic InternalServerError(500)
response. Add catch(const Poco::IOException&) — covering the whole
Poco::Net::NetException family (connection reset/refused, DNS, TLS) plus generic
IO — and catch(const NetException&) for ClickHouse's own DB::NetException(DNS_ERROR)
from makeHTTPSession, which is not a Poco::IOException. Both mirror the existing
Poco::TimeoutException arm and throw Azure::Core::Http::TransportException, so
network errors are retried unconditionally by the SDK rather than relying on 500
being in the retryable status set (matches the S3 client at src/IO/S3/PocoHTTPClient.cpp).

Add azure_inject_poco_network_error[_once] failpoints and a "network" case in
the test_azure_403_handling suite.

Follow-up to ClickHouse#112871, addresses review comment
ClickHouse#112871 (comment)
@arsenmuk arsenmuk added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 5, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 5, 2026
Backport #112871 to 26.7: Fix transient Azure errors misreported as broken data parts
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 15, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 23, 2026
On master the Azure transport now throws `TransportException` for a
timeout or a broken connection (ClickHouse#112871, ClickHouse#115269) instead of
returning a synthetic 408 or 500 from `PocoAzureHTTPClient`.
`TransportException` carries no status code, so the status-only
classifier reported a timed-out rename as a definite failure
("Rename failed: HTTP 0") and the destructor then claimed the file was
unchanged, although the rename may have been applied. The classifier
now takes the exception and treats a transport failure as ambiguous,
which yields "commit status unknown" as for 408 and 5xx.

A transport failure is also rendered with its explanation, which is in
`what` rather than `Message`, instead of as `HTTP 0: `, and it is logged
to `system.blob_storage_log` with a non-zero error code through
`getAzureErrorCodeForLog`, as `WriteBufferFromAzureBlobStorage` does.

`isRetryableAzureException` now retries a 403 unconditionally (ClickHouse#112871), so a
403 on the staging create is retried on the same staging name. The
test for that path now checks that only one staging name is used,
which is what it is about, rather than the number of requests.

The test's request classifier now uses `contains`, which clang-tidy 22,
the compiler version master pins now, requires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure 403 leads to POTENTIALLY_BROKEN_DATA_PART

7 participants