From 2214c1d3d524a31fddeffe8b862f5f9522a9f29e 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 4ca88c03bd..737657cbaf 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 b7128cf694..2cc522ac45 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 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc } } -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 @@ bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId 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 eae8e76fd9b6d834289a821e65849280dee2dad1 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 2cc522ac45..4db7d9762e 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 4ecaed47df5127cec0b1f1d2bc7224cfc2129691 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 4db7d9762e..b2d1793ce5 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 c48ecf8d60f555059435f923bcab3744fc1bd46e 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 737657cbaf..349dfc3264 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 b2d1793ce5..4c55cc5d34 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -146,7 +146,8 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc 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 @@ bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId }]; 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; }