From c3ba871f3633297046341b7760add409063f2512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Fuch=C3=9F?= Date: Mon, 15 May 2023 23:35:12 +0200 Subject: [PATCH 1/3] Add config variable for curl timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the config variable for curl calls ("remote_curl_timeout"). E.g., needed for nextcloud federation. Signed-off-by: Dominik Fuchß --- config/config.sample.php | 5 +++++ lib/private/Files/Storage/DAV.php | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 94b8a5d055245..4330b0cda609d 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -289,6 +289,11 @@ */ 'session_lifetime' => 60 * 60 * 24, +/** + * The timeout for requests to remote servers (e.g., needed for federated shares). + */ +'remote_curl_timeout' => 30, + /** * `true` enabled a relaxed session timeout, where the session timeout would no longer be * handled by Nextcloud but by either the PHP garbage collection or the expiration of diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 733aa10cde6d2..366ab4dda14dd 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -373,7 +373,9 @@ public function fopen($path, $mode) { ->newClient() ->get($this->createBaseUri() . $this->encodePath($path), [ 'auth' => [$this->user, $this->password], - 'stream' => true + 'stream' => true, + // set download timeout for users with slow connections or large files + 'timeout' => \OC::$server->getConfig()->getSystemValueInt('remote_curl_timeout', 30) ]); } catch (\GuzzleHttp\Exception\ClientException $e) { if ($e->getResponse() instanceof ResponseInterface @@ -530,7 +532,9 @@ protected function uploadFile($path, $target) { ->newClient() ->put($this->createBaseUri() . $this->encodePath($target), [ 'body' => $source, - 'auth' => [$this->user, $this->password] + 'auth' => [$this->user, $this->password], + // set upload timeout for users with slow connections or large files + 'timeout' => \OC::$server->getConfig()->getSystemValueInt('remote_curl_timeout', 30) ]); $this->removeCachedFile($target); From a4a57409db7500a781f339d52999183de83b6ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Fuch=C3=9F?= Date: Sun, 11 Jun 2023 15:16:38 +0200 Subject: [PATCH 2/3] Changes after code review. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Fuchß --- config/config.sample.php | 4 ++-- lib/private/Files/Storage/DAV.php | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 4330b0cda609d..c87e1cad9fa4c 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -290,9 +290,9 @@ 'session_lifetime' => 60 * 60 * 24, /** - * The timeout for requests to remote servers (e.g., needed for federated shares). + * The timeout in seconds for requests to servers made by the DAV component (e.g., needed for federated shares). */ -'remote_curl_timeout' => 30, +'davstorage.request_timeout' => 30, /** * `true` enabled a relaxed session timeout, where the session timeout would no longer be diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 366ab4dda14dd..a769f799ed360 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -93,6 +93,9 @@ class DAV extends Common { protected LoggerInterface $logger; protected IEventLogger $eventLogger; + /** @var int */ + private $timeout; + /** * @param array $params * @throws \Exception @@ -135,6 +138,8 @@ public function __construct($params) { } $this->logger = \OC::$server->get(LoggerInterface::class); $this->eventLogger = \OC::$server->get(IEventLogger::class); + // This timeout value will be used for the download and upload of files + $this->timeout = \OC::$server->getConfig()->getSystemValueInt('davstorage.request_timeout', 30); } protected function init() { @@ -375,7 +380,7 @@ public function fopen($path, $mode) { 'auth' => [$this->user, $this->password], 'stream' => true, // set download timeout for users with slow connections or large files - 'timeout' => \OC::$server->getConfig()->getSystemValueInt('remote_curl_timeout', 30) + 'timeout' => $this->timeout ]); } catch (\GuzzleHttp\Exception\ClientException $e) { if ($e->getResponse() instanceof ResponseInterface @@ -534,7 +539,7 @@ protected function uploadFile($path, $target) { 'body' => $source, 'auth' => [$this->user, $this->password], // set upload timeout for users with slow connections or large files - 'timeout' => \OC::$server->getConfig()->getSystemValueInt('remote_curl_timeout', 30) + 'timeout' => $this->timeout ]); $this->removeCachedFile($target); From e3f6a13e148e6410ec64239a4d7b9e6ca358c81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Fuch=C3=9F?= Date: Mon, 12 Jun 2023 19:40:39 +0200 Subject: [PATCH 3/3] Fix deprecated method call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Fuchß --- lib/private/Files/Storage/DAV.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index a769f799ed360..b5b8b548787ef 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -51,6 +51,7 @@ use OCP\Files\StorageNotAvailableException; use OCP\Http\Client\IClientService; use OCP\ICertificateManager; +use OCP\IConfig; use OCP\Util; use Psr\Http\Message\ResponseInterface; use Sabre\DAV\Client; @@ -139,7 +140,7 @@ public function __construct($params) { $this->logger = \OC::$server->get(LoggerInterface::class); $this->eventLogger = \OC::$server->get(IEventLogger::class); // This timeout value will be used for the download and upload of files - $this->timeout = \OC::$server->getConfig()->getSystemValueInt('davstorage.request_timeout', 30); + $this->timeout = \OC::$server->get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30); } protected function init() {