From 43081fe169056f642788629b23b0934acb527b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 19 Feb 2020 08:59:59 +0100 Subject: [PATCH 1/2] Better handling of DB timeouts on long downloads --- .../Files/Storage/Wrapper/Checksum.php | 19 ++++++++++++------- lib/private/Files/View.php | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Checksum.php b/lib/private/Files/Storage/Wrapper/Checksum.php index 28dc63690ace..664316974cfa 100644 --- a/lib/private/Files/Storage/Wrapper/Checksum.php +++ b/lib/private/Files/Storage/Wrapper/Checksum.php @@ -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; @@ -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']); + } } /** diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 0bc900dfa444..fe9c2aa25919 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -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; From a7eeab4228e34ea798dc5dc86416730c1299282a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 19 Feb 2020 10:15:05 +0100 Subject: [PATCH 2/2] Add changelog item --- changelog/unreleased/36978 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 changelog/unreleased/36978 diff --git a/changelog/unreleased/36978 b/changelog/unreleased/36978 new file mode 100644 index 000000000000..ea79fc820175 --- /dev/null +++ b/changelog/unreleased/36978 @@ -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