wsd/LOOLWSD.cpp | 73 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 35 deletions(-)
New commits: commit 3c6492101b967f103036ea2b4b9e627dd4ee29a8 Author: Ashod Nakashian <[email protected]> Date: Fri Feb 23 20:59:59 2018 -0500 wsd: refactor diskpace and session limit checks Checks are now done after adding new sessions to DocBroker rather than before, so the current session being added doesn't need special handling. The checks for diskspace is separated from that of the number of sessions as they are unrelated. Also, no reason to do the checks for convert-to requests, since these don't have interactive clients, rather the connections are closed after the conversion. Change-Id: Idc50cd38263e6779acdeed72d5eb876a3228c96e Reviewed-on: https://gerrit.libreoffice.org/52680 Reviewed-by: Jan Holesovsky <[email protected]> Tested-by: Jan Holesovsky <[email protected]> diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 3b645fe8f..48e915ab8 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -218,23 +218,24 @@ inline void shutdownLimitReached(WebSocketHandler& ws) } #endif -inline void infoLimitReached(const WebSocketHandler* ws) +inline void checkSessionLimitsAndWarnClients() { - const std::string info = Poco::format(PAYLOAD_INFO_LIMIT_REACHED, LOOLWSD::MaxDocuments, LOOLWSD::MaxConnections); - LOG_INF("Sending client 'limitreached' message: " << info); - - try - { - Util::alertAllUsers(info); - ws->sendMessage(info); - } - catch (const std::exception& ex) + if (DocBrokers.size() > LOOLWSD::MaxDocuments || LOOLWSD::NumConnections >= LOOLWSD::MaxConnections) { - LOG_ERR("Error while shuting down socket on reaching limit: " << ex.what()); + const std::string info = Poco::format(PAYLOAD_INFO_LIMIT_REACHED, LOOLWSD::MaxDocuments, LOOLWSD::MaxConnections); + LOG_INF("Sending client 'limitreached' message: " << info); + + try + { + Util::alertAllUsers(info); + } + catch (const std::exception& ex) + { + LOG_ERR("Error while shuting down socket on reaching limit: " << ex.what()); + } } } - /// Internal implementation to alert all clients /// connected to any document. void alertAllUsersInternal(const std::string& msg) @@ -252,6 +253,24 @@ void alertAllUsersInternal(const std::string& msg) docBroker->addCallback([msg, docBroker](){ docBroker->alertAllUsers(msg); }); } } + +static void checkDiskSpaceAndWarnClients(const bool cacheLastCheck) +{ + try + { + const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems(cacheLastCheck); + if (!fs.empty()) + { + LOG_WRN("File system of [" << fs << "] is dangerously low on disk space."); + alertAllUsersInternal("error: cmd=internal kind=diskfull"); + } + } + catch (const std::exception& exc) + { + LOG_WRN("Exception while checking disk-space and warning clients: " << exc.what()); + } +} + } /// Remove dead and idle DocBrokers. @@ -302,12 +321,7 @@ static int forkChildren(const int number) if (number > 0) { - const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems(false); - if (!fs.empty()) - { - LOG_WRN("File system of " << fs << " dangerously low on disk space"); - alertAllUsersInternal("error: cmd=internal kind=diskfull"); - } + checkDiskSpaceAndWarnClients(false); #ifdef KIT_IN_PROCESS forkLibreOfficeKit(LOOLWSD::ChildRoot, LOOLWSD::SysTemplate, LOOLWSD::LoTemplate, LO_JAIL_SUBPATH, number); @@ -1507,23 +1521,6 @@ static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHand const std::string statusReady = "statusindicator: ready"; LOG_TRC("Sending to Client [" << statusReady << "]."); ws->sendMessage(statusReady); - - const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems(); - if (!fs.empty()) - { - LOG_WRN("File system of [" << fs << "] is dangerously low on disk space."); - const std::string diskfullMsg = "error: cmd=internal kind=diskfull"; - // Alert all existing sessions - Util::alertAllUsers(diskfullMsg); - ws->sendMessage(diskfullMsg); - } -#if !ENABLE_SUPPORT_KEY - // Users of development versions get just an info when reaching max documents or connections - if (DocBrokers.size() > LOOLWSD::MaxDocuments || LOOLWSD::NumConnections >= LOOLWSD::MaxConnections) - { - infoLimitReached(ws); - } -#endif } // In case of WOPI, if this session is not set as readonly, it might be set so @@ -2285,6 +2282,12 @@ private: // Add and load the session. docBroker->addSession(clientSession); + + checkDiskSpaceAndWarnClients(true); +#if !ENABLE_SUPPORT_KEY + // Users of development versions get just an info when reaching max documents or connections + checkSessionLimitsAndWarnClients(); +#endif } catch (const UnauthorizedRequestException& exc) { _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
