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

Better handling of DB timeouts on long downloads #36978

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions changelog/unreleased/36978
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Bugfix: Avoid unneeded DB connections after a long download

After a long download, we needed to return the filesize, which needed a connection
to the DB. The DB could have ended the connection due to an inactivity timeout.
Now, the filesize is fetched before starting the download, so this timeout shouldn't
happen any longer.
We still need to update the checksum after the download is finished. In this case,
we just log an error message and keep going.

https://github.com/owncloud/core/pull/36978
19 changes: 12 additions & 7 deletions lib/private/Files/Storage/Wrapper/Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace OC\Files\Storage\Wrapper;

use Icewind\Streams\CallbackWrapper;
use Doctrine\DBAL\Exception\DriverException;
use OC\Files\Stream\Checksum as ChecksumStream;
use OCP\Files\IHomeStorage;

Expand Down Expand Up @@ -131,14 +132,18 @@ private function isReadWriteStream($mode) {
*/
public function onClose() {
$cache = $this->getCache();
foreach ($this->pathsInCacheWithoutChecksum as $cacheId => $path) {
$cache->update(
$cacheId,
['checksum' => self::getChecksumsInDbFormat($path)]
);
}
try {
foreach ($this->pathsInCacheWithoutChecksum as $cacheId => $path) {
$cache->update(
$cacheId,
['checksum' => self::getChecksumsInDbFormat($path)]
);
}

$this->pathsInCacheWithoutChecksum = [];
$this->pathsInCacheWithoutChecksum = [];
} catch (DriverException $ex) {
\OC::$server->getLogger()->error($ex->getMessage(), ['app' => 'checksum']);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ public function readfile($path) {
$handle = $this->fopen($path, 'rb');
if ($handle) {
$chunkSize = 8192; // 8 kB chunks
$size = $this->filesize($path);
while (!\feof($handle)) {
echo \fread($handle, $chunkSize);
\flush();
}
$size = $this->filesize($path);
return $size;
}
return false;
Expand Down