Skip to content

Commit

Permalink
Merge pull request #36978 from owncloud/long_downloads
Browse files Browse the repository at this point in the history
Better handling of DB timeouts on long downloads
  • Loading branch information
micbar authored Mar 2, 2020
2 parents aeb174a + a7eeab4 commit a165f2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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

0 comments on commit a165f2b

Please sign in to comment.