From 1f8c0d9319da6c08bea8f07e9d272625ff788745 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Oct 2024 13:42:21 +0800 Subject: [PATCH 1/4] Do not attempt to reach out to FileProviderExt every single time we want to check if it is reachable Only check every 60 seconds, this way we do not freeze the client for 3 seconds every time that we want to check the reachability while the extension is unreachable Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc.h | 4 +++- src/gui/macOS/fileproviderxpc_mac.mm | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/gui/macOS/fileproviderxpc.h b/src/gui/macOS/fileproviderxpc.h index 4ca88c03bd5be..737657cbaf3d6 100644 --- a/src/gui/macOS/fileproviderxpc.h +++ b/src/gui/macOS/fileproviderxpc.h @@ -14,6 +14,7 @@ #include #include +#include #include "accountstate.h" @@ -34,7 +35,7 @@ class FileProviderXPC : public QObject public: explicit FileProviderXPC(QObject *parent = nullptr); - [[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId) const; + [[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId); // Returns enabled and set state of fast enumeration for the given extension [[nodiscard]] std::optional> fastEnumerationStateForExtension(const QString &extensionAccountId) const; @@ -53,6 +54,7 @@ private slots: private: QHash _clientCommServices; + QDateTime _lastUnreachableTime; }; } // namespace OCC::Mac diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index b7128cf6941c8..2cc522ac455dc 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -22,6 +22,7 @@ namespace { constexpr int64_t semaphoreWaitDelta = 3000000000; // 3 seconds + constexpr auto reachableRetryTimeout = 60; // 60 seconds } namespace OCC::Mac { @@ -143,12 +144,19 @@ } } -bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) const +bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) { + if (_lastUnreachableTime.isValid() && _lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) { + qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. " + << "Not checking again"; + return false; + } + const auto service = (NSObject *)_clientCommServices.value(extensionAccountId); if (service == nil) { return false; } + __block auto response = false; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [service getExtensionAccountIdWithCompletionHandler:^(NSString *const, NSError *const) { @@ -156,6 +164,11 @@ dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, semaphoreWaitDelta)); + + if (!response) { + qCWarning(lcFileProviderXPC) << "Could not reach file provider extension."; + _lastUnreachableTime = QDateTime::currentDateTime(); + } return response; } From 536f370c2e81fc1fc2f04895f05da50c9c6e6147 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Oct 2024 13:43:56 +0800 Subject: [PATCH 2/4] Slash semaphore wait delta on reachability down to 1 second Any longer does not really yield any positive result and freezes the client for longer Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index 2cc522ac455dc..4db7d9762e0c3 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -21,7 +21,7 @@ #include "gui/macOS/fileproviderxpc_mac_utils.h" namespace { - constexpr int64_t semaphoreWaitDelta = 3000000000; // 3 seconds + constexpr int64_t semaphoreWaitDelta = 1000000000; // 1 seconds constexpr auto reachableRetryTimeout = 60; // 60 seconds } From 532201a4767f757f149415519711a09da6ca5143 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Oct 2024 13:48:38 +0800 Subject: [PATCH 3/4] Increase reachability retry timeout Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index 4db7d9762e0c3..b2d1793ce5b70 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -22,7 +22,7 @@ namespace { constexpr int64_t semaphoreWaitDelta = 1000000000; // 1 seconds - constexpr auto reachableRetryTimeout = 60; // 60 seconds + constexpr auto reachableRetryTimeout = 300; // seconds } namespace OCC::Mac { From 568243100dc9d1f4b583ec98056dd73737ac6748 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Oct 2024 13:56:30 +0800 Subject: [PATCH 4/4] Store reachability of FileProviderExt by respective account Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc.h | 2 +- src/gui/macOS/fileproviderxpc_mac.mm | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gui/macOS/fileproviderxpc.h b/src/gui/macOS/fileproviderxpc.h index 737657cbaf3d6..349dfc3264034 100644 --- a/src/gui/macOS/fileproviderxpc.h +++ b/src/gui/macOS/fileproviderxpc.h @@ -54,7 +54,7 @@ private slots: private: QHash _clientCommServices; - QDateTime _lastUnreachableTime; + QHash _unreachableAccountExtensions; }; } // namespace OCC::Mac diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index b2d1793ce5b70..4c55cc5d34490 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -146,7 +146,8 @@ bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) { - if (_lastUnreachableTime.isValid() && _lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) { + const auto lastUnreachableTime = _unreachableAccountExtensions.value(extensionAccountId); + if (lastUnreachableTime.isValid() && lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) { qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. " << "Not checking again"; return false; @@ -165,9 +166,11 @@ }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, semaphoreWaitDelta)); - if (!response) { + if (response) { + _unreachableAccountExtensions.remove(extensionAccountId); + } else { qCWarning(lcFileProviderXPC) << "Could not reach file provider extension."; - _lastUnreachableTime = QDateTime::currentDateTime(); + _unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime()); } return response; }