From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 999681FF0B6 for ; Thu, 12 Nov 2026 19:02:19 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 22111216B9; Thu, 12 Nov 2026 19:02:09 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox v3 07/11] s3-client: add helper to fetch object contents with retry Date: Thu, 12 Nov 2026 19:01:15 +0100 Message-ID: <20261112180119.660923-8-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112180119.660923-1-c.ebner@proxmox.com> References: <20261112180119.660923-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794506502524 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.407 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: VOGORBYVBTJXYO4FV37J4VY5N6O2CU6J X-Message-ID-Hash: VOGORBYVBTJXYO4FV37J4VY5N6O2CU6J X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 e0e01d81..2eb5fb35 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, 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