Repository navigation
Fix nested S3 request retries and read the error an S3 server sends before the whole request body - #124557
Conversation
`Client::doRequestWithRetryNetworkErrors` retried every retryable error outcome returned by the AWS SDK, but the SDK's own retry loop has already run the same `RetryStrategy` with `max_retries = s3_retry_attempts` for it, so a persistent retryable error was attempted `(s3_retry_attempts + 1)^2` times (251001 with the default of 500). The outer outcome retry was introduced in ClickHouse#84854 only for `s3_slow_all_threads_after_retryable_error`, where the SDK gets `max_retries = 1`; ClickHouse#90216 rewrote the loop and dropped that condition. Restore it: with the flag off, a non-success outcome is returned as is. Exceptions thrown out of the SDK while it reads a response body (the case ClickHouse#90216 added the loop for) are still retried by the outer loop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…request body A server may answer a request it rejects right after reading its header and close the connection with the body unread. MinIO does this for an `UploadPart` whose multipart upload no longer exists (`404 NoSuchUpload`, e.g. after its stale-upload expiry). `PocoHTTPClient` writes the whole body before reading the response, so the write fails with `Broken pipe` or `Connection reset by peer`; Poco keeps that send error in the session and `receiveResponse` rethrows it before reading anything, so the 404 is never seen and the request is retried as a network error until the retry budget is spent, then fails with the network error instead of `NoSuchUpload`. When sending the body over plain HTTP fails with a `Poco::IOException` and response data is already waiting on the socket (non-blocking probe `getSocketState`), read that response with the new `HTTPClientSession::receiveEarlyResponse` and use it if its status is an error (>= 300). Otherwise the send error is rethrown as before. TLS is excluded: OpenSSL allows no further I/O after a failed `SSL_write`, so over HTTPS such an error is still retried as a network error (bounded by `s3_retry_attempts` after the previous commit). The `no_such_upload` action of the S3 mock gets an `early` mode that answers without reading the body and resets the connection, as MinIO does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the receiveEarlyResponse doc to its contract and drop the expired-upload example from the PocoHTTPClient catch comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Independent model review (codex, 1 finding) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261008-062000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261008-044000 |
|
Workflow [PR], commit [6eb6402] Summary: ✅
AI ReviewSummaryThis PR fixes two S3-specific regressions: it stops the outer ClickHouse retry loop from re-retrying retryable AWS SDK outcomes after the SDK has already exhausted its own retry budget, and it adds a plain-HTTP early-response path so an S3 server error sent before the full request body is read is surfaced as the server's HTTP error instead of as a terminal Final Verdict✅ No new review findings from me on the current diff. LLVM Coverage ReportMeasured on commit 6eb6402.
Changed lines: Changed C/C++ lines covered: 20/20 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes10 object files changed (-12.41 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units283 translation units recompiled, 2225 s compile time in total, 283 of them have a recent master baseline. |
| /// Drops the unsent rest of the request, which rethrows the send error. | ||
| try | ||
| { | ||
| flushRequest(); |
There was a problem hiding this comment.
flushRequest() only rethrows the send error that the caller is already handling (the stored networkException(); the body stream is already bad, so the flush itself writes nothing). The catch drops that copy, and the caller rethrows the original exception with throw; whenever no response is read. Agreed that it is not visible from the code. This goes away in the replacement: #124326 (comment)
| || !session->receiveEarlyResponse(poco_response) | ||
| || poco_response.getStatus() < Poco::Net::HTTPResponse::HTTP_MULTIPLE_CHOICES) | ||
| throw; | ||
| LOG_DEBUG(log, "Failed to send the request body to {}, using the response the server has already sent: {}", |
There was a problem hiding this comment.
Do not understand, we just catch an exception here and if connection is not secure just drop it / mute it? Not sure it is correct.
There was a problem hiding this comment.
No, it is never muted: throw; rethrows the original IOException in every case except one: plain HTTP, data already waiting on the socket, a complete response header parsed, and status >= 300. Only then the send error is replaced by that response, which goes through the normal S3 error handling (here NoSuchUpload, not retried), and the send error is logged at DEBUG. Over HTTPS it is always rethrown.
| HTTPHeaderInputStream his(*this); | ||
| try | ||
| { | ||
| response.read(his); |
There was a problem hiding this comment.
Here we lose the exception description. If something happened here we just return false.
There was a problem hiding this comment.
Right: a parse failure returns false, the caller then rethrows the original send error, and the parse error text is lost. The replacement does not read after a failed write at all: #124326 (comment)
| /// TLS allows no I/O after a failed write. | ||
| if (session->secure() | ||
| || DB::getSocketState(session->socket()) != DB::SocketState::DataPending | ||
| || !session->receiveEarlyResponse(poco_response) |
There was a problem hiding this comment.
This session already throw the exception, current one, but in receiveEarlyResponse method we try to read from that session again.
There was a problem hiding this comment.
Yes, on purpose: only the write failed (EPIPE / ECONNRESET). On a plain TCP socket on Linux, the bytes the server sent before closing stay in the receive queue and can still be read; that is how the 404 is read in the MinIO repro. TLS forbids any I/O after a fatal SSL_write, hence plain HTTP only. I agree this is the wrong approach and plan Expect: 100-continue instead: #124326 (comment)
Drop the early-error-response part (`HTTPClientSession` and `PocoHTTPClient` changes, the `early` mode of the `no_such_upload` mock and its test): the mock action it extends comes from #118829, which is not on 26.9, and #130514 replaces this approach on master with `Expect: 100-continue`. What remains is fe7dab9 (no outer retry of an error the SDK has already retried), the same tree as the resolution proposed and tested by groeneai. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #124557 to 26.9: Fix nested S3 request retries and read the error an S3 server sends before the whole request body
…error an S3 server sends before the whole request body
Cherry pick #124557 to 26.8: Fix nested S3 request retries and read the error an S3 server sends before the whole request body
…error an S3 server sends before the whole request body
Backport #124557 to 26.8: Fix nested S3 request retries and read the error an S3 server sends before the whole request body
Backport #124557 to 26.9: Fix nested S3 request retries and read the error an S3 server sends before the whole request body
…error an S3 server sends before the whole request body
…error an S3 server sends before the whole request body
The tests-only part of ClickHouse#131102, unchanged: the `lingering` mode of `NoSuchUploadAction` in the S3 mock, the early-error rows of `test_early_error_response_at_upload_is_not_retried`, and the `SilkFiberSocketTest.HTTPRequestBody` gtest. They pass on master, where plain HTTP is handled by the read of ClickHouse#124557. Related: ClickHouse#131084 Co-authored-by: Sema Checherinda <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #124326
Related: #90216
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed S3 requests that keep failing with a retryable error being attempted
(s3_retry_attempts + 1)^2times instead ofs3_retry_attempts + 1. Fixed an error that a plain-HTTP S3 endpoint sends before reading the whole request body (for exampleNoSuchUploadfor an expired multipart upload) being retried as aBroken pipenetwork error instead of being reported. Closes #124326.Description
On 26.9.12.8, an
INSERT INTO FUNCTION s3(...)whose multipart upload the server aborts before the last part sends that part(s3_retry_attempts + 1)^2times (251,001 with the default) and fails with a network error instead ofNoSuchUpload. Two defects:Client::doRequestWithRetryNetworkErrorsretries every retryable error the SDK returns, but the SDK has already retried its3_retry_attemptstimes. Slow down all backup threads after S3 retryable errors, including ‘SlowDown’ #84854 added this outer retry only fors3_slow_all_threads_after_retryable_error(where the SDK gets one retry); retry network errors when s3 library parse xml response #90216 dropped that condition; this restores it. Exceptions thrown out of the SDK while it reads a response body are still retried by the outer loop.404 NoSuchUploadright after the request header and resets the connection.PocoHTTPClientwrites the whole body first, the write fails, and Poco rethrows that send error instead of returning the response. Now, when the body send fails over plain HTTP with response data already waiting on the socket, that response is read (newHTTPClientSession::receiveEarlyResponse) and used if its status is >= 300. Over HTTPS (OpenSSL allows no I/O after a failed write) such an error is still retried as a network error, but onlys3_retry_attempts + 1times. The Azure transport has the same shape and is not changed.Validation with MinIO,
s3_retry_attempts = 3: 26.9.12.8 and master send the dead part 16 times and read no response; with this PR it is sent once and the query fails withNoSuchUpload(the same with the default 500). Over HTTPS: 16 -> 4.test_when_error_is_retriednow checks the attempt count (37 on master, 7 here); new testtest_early_error_response_at_upload_is_not_retried.Changes the same request-body block of
PocoHTTPClientas #116222.Server log, MinIO, s3_retry_attempts = 3
26.9.12.8 (16 such lines, the SDK count restarts 4 times):
This PR:
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124557]
Version info
26.10.1.2056-master(included in26.10and later)