Skip to content

Commit 743abff

Browse files
chore(s3): readobject retry implementation cleanup
Signed-off-by: Josh <[email protected]>
1 parent a4c8bba commit 743abff

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/private/Files/ObjectStore/S3ObjectTrait.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-FileCopyrightText: 2017-2026 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-License-Identifier: AGPL-3.0-or-later
66
*/
77
namespace OC\Files\ObjectStore;
@@ -49,7 +49,7 @@ public function readObject($urn) {
4949
// via an abstract method (e.g. getLogger()) rather than inline container lookups
5050
$logger = \OCP\Server::get(\Psr\Log\LoggerInterface::class);
5151

52-
$fh = SeekableHttpStream::open(function ($range) use ($urn, $maxAttempts, &$lastError, $logger) {
52+
$fh = SeekableHttpStream::open(function ($range) use ($urn, $maxAttempts, &$lastError, &$firstError, $logger) {
5353
$command = $this->getConnection()->getCommand('GetObject', [
5454
'Bucket' => $this->bucket,
5555
'Key' => $urn,
@@ -134,8 +134,14 @@ public function readObject($urn) {
134134
}
135135

136136
// fopen returned false - i.e. connection-level failure (DNS, timeout, TLS, etc.)
137-
// log occurences for operator visibility even if retried
138-
$lastError = "connection failure while reading object $urn range $range on attempt $attempt/$maxAttempts (no HTTP response received)";
137+
// log occurrences for operator visibility even if retried
138+
$currentError = "connection failure while reading object $urn range $range on attempt $attempt/$maxAttempts (no HTTP response received)";
139+
if ($firstError === 'unknown error') {
140+
$firstError = $currentError;
141+
} else {
142+
$lastError = $currentError;
143+
}
144+
139145
$logger->warning($lastError, ['app' => 'objectstore']);
140146

141147
if ($attempt < $maxAttempts) {
@@ -235,7 +241,7 @@ private function formatS3ReadError(
235241

236242
if ($statusCode === 416) {
237243
return sprintf(
238-
'HTTP 416 reading object %s range %s on attempt %d/%d: requested range not satisfiable',
244+
'HTTP 416 reading object %s range %s on attempt %d/%d: requested range not satisfiable [%s - %s (RequestId: %s, ExtendedRequestId: %s)]',
239245
$urn,
240246
$range,
241247
$attempt,

0 commit comments

Comments
 (0)