From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox v5 07/12] s3-client: add helper to fetch object contents with retry
Date: Mon, 16 Nov 2026 10:54:29 +0100 [thread overview]
Message-ID: <20261116095434.110541-8-c.ebner@proxmox.com> (raw)
In-Reply-To: <20261116095434.110541-1-c.ebner@proxmox.com>
Sending requests is retried on connection errors and some error
responses, but the connection might still break while receiving the
response body.
Add a helper which fetches the object and collects its contents,
repeating the request with the jittered backoff for transient errors
if collecting the body fails, as such failures are caused by broken
connections. A new request is required, as a partially received body
cannot be resumed.
This is intended for callers which would collect the objects body
data right away anyways and allows to not have to reimplement custom
retry logic for that.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
proxmox-s3-client/src/client.rs | 36 +++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/proxmox-s3-client/src/client.rs b/proxmox-s3-client/src/client.rs
index 12d9a206..aae3961a 100644
--- a/proxmox-s3-client/src/client.rs
+++ b/proxmox-s3-client/src/client.rs
@@ -660,6 +660,42 @@ impl S3Client {
response_reader.get_object_response().await
}
+ /// Fetch an object from object store and collect its contents.
+ ///
+ /// Returns `Ok(None)` if the object does not exist. Sending the request is retried by the
+ /// client already, but the connection can still break while the response body is being
+ /// received. Since a partially received body cannot be resumed, the whole request is repeated
+ /// with backoff in that case, up to the same number of attempts as for sending requests.
+ pub async fn get_object_content(
+ &self,
+ object_key: S3ObjectKey,
+ ) -> Result<Option<Bytes>, Error> {
+ let mut retry = 0;
+ loop {
+ let Some(response) = self.get_object(object_key.clone()).await? else {
+ return Ok(None);
+ };
+
+ let collect_result =
+ tokio::time::timeout(S3_HTTP_REQUEST_TIMEOUT, response.content.collect())
+ .await
+ .context("timeout while collecting object contents")
+ .and_then(|res| res.context("failed to collect object contents"));
+
+ match collect_result {
+ Ok(content) => return Ok(Some(content.to_bytes())),
+ Err(err) => {
+ if retry >= MAX_S3_HTTP_REQUEST_RETRY - 1 {
+ return Err(err);
+ }
+ tokio::time::sleep(retry_backoff_with_jitter(RetryReason::Transient, retry))
+ .await;
+ retry += 1;
+ }
+ }
+ }
+ }
+
/// Returns some or all (up to 1,000) of the objects in a bucket with each request.
/// See reference docs: https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html
pub async fn list_objects_v2(
--
2.47.3
next prev parent reply other threads:[~2026-11-16 9:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 9:54 [PATCH proxmox{,-backup} v5 00/12] fix #7606: verify: s3: handle transient fetch errors and add retry Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox v5 01/12] s3-client: also retry requests on bad gateway responses Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox v5 02/12] s3-client: distinguish transient errors and throttled requests Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox v5 03/12] s3-client: detect throttling request from the response body on error Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox v5 04/12] s3-client: avoid retry bursts by adding jitter to retry backoff delay Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox v5 05/12] s3-client: honor response header directed retry delays Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox v5 06/12] s3-client: add additional backoff delay between upload retries Christian Ebner
2026-11-16 9:54 ` Christian Ebner [this message]
2026-11-16 9:54 ` [PATCH proxmox v5 08/12] s3-client: add shared rate limiter based retry quota Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox-backup v5 09/12] s3: retry fetching object contents on body collection errors Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox-backup v5 10/12] datastore: snapshot: propagate errors in manifest update callback Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox-backup v5 11/12] fix #7606: verify: s3: handle transient chunk load errors Christian Ebner
2026-11-16 9:54 ` [PATCH proxmox-backup v5 12/12] verify: s3: stop early if the endpoint appears unreachable Christian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116095434.110541-8-c.ebner@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox