[Libreoffice-commits] online.git: wsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jun 14 14:09:06 UTC 2018


 wsd/LOOLWSD.cpp |   73 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 35 deletions(-)

New commits:
commit fbc86814062b4bb55ac48a526473580444e11ec0
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
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/52418
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index a66d0306d..25ec59258 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -216,23 +216,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)
@@ -250,6 +251,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.
@@ -300,12 +319,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);
@@ -1514,23 +1528,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
@@ -2332,6 +2329,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)
                             {


More information about the Libreoffice-commits mailing list