Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S3 error handling #22514

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,13 @@ public function writeStream(string $path, $stream, int $size = null): int {

$exists = $this->getCache()->inCache($path);
$uploadPath = $exists ? $path : $path . '.part';
$fileId = $this->getCache()->put($uploadPath, $stat);

if ($exists) {
$fileId = $stat['fileid'];
} else {
$fileId = $this->getCache()->put($uploadPath, $stat);
}

$urn = $this->getURN($fileId);
try {
//upload to object storage
Expand All @@ -461,19 +467,33 @@ public function writeStream(string $path, $stream, int $size = null): int {
if (is_resource($countStream)) {
fclose($countStream);
}
$stat['size'] = $size;
} else {
$this->objectStore->writeObject($urn, $stream);
}
} catch (\Exception $ex) {
$this->getCache()->remove($uploadPath);
$this->logger->logException($ex, [
'app' => 'objectstore',
'message' => 'Could not create object ' . $urn . ' for ' . $path,
]);
if (!$exists) {
/*
* Only remove the entry if we are dealing with a new file.
* Else people lose access to existing files
*/
$this->getCache()->remove($uploadPath);
$this->logger->logException($ex, [
'app' => 'objectstore',
'message' => 'Could not create object ' . $urn . ' for ' . $path,
]);
} else {
$this->logger->logException($ex, [
'app' => 'objectstore',
'message' => 'Could not update object ' . $urn . ' for ' . $path,
]);
}
throw $ex; // make this bubble up
}

if (!$exists) {
if ($exists) {
$this->getCache()->update($fileId, $stat);
Copy link
Member

Choose a reason for hiding this comment

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

what stats are being updated here? the size is already updated in the CountWrapper callback

Copy link
Member Author

Choose a reason for hiding this comment

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

Mtime etc

} else {
if ($this->objectStore->objectExists($urn)) {
$this->getCache()->move($uploadPath, $path);
} else {
Expand Down