[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-0' - wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

Tor Lillqvist tml at collabora.com
Tue Jan 10 21:10:33 UTC 2017


 wsd/DocumentBroker.cpp |    2 ++
 wsd/DocumentBroker.hpp |    4 ++++
 wsd/LOOLWSD.cpp        |   27 +++++++++++++++++++++++++++
 3 files changed, 33 insertions(+)

New commits:
commit 47e5fb48eb982e8b65241b2de5b1424c4ab59c56
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed Dec 14 18:12:57 2016 +0200

    Bluntly close sessions that have been idle for more than an hour
    
    By that time the loleaflet code has already done the greying-out (this
    happens at the latest after 10 minutes of inactivity) and marked them
    as 'inactive'. Bluntly closing the session seems to work out fine, no
    new horribly alarming message is displayed by the loleaflet code in
    addition to the already visible 'Inactive document ...' one.
    
    Change-Id: I420f0d7530194e6c8d6f34d7985ab810cde5a76a
    (cherry picked from commit 36f3dece7c6ecc8bd0ccb8caacbe8e7c31ab47f7)

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 21baad3..96ec511 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -11,6 +11,7 @@
 #include "config.h"
 
 #include <cassert>
+#include <ctime>
 #include <fstream>
 #include <sstream>
 
@@ -1038,6 +1039,7 @@ void DocumentBroker::closeDocument(const std::string& reason)
 
 void DocumentBroker::updateLastActivityTime()
 {
+    _lastActivity = std::time(nullptr);
     Admin::instance().updateLastActivityTime(_docKey);
 }
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0ea84b8..27298e9 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -301,6 +301,8 @@ public:
 
     void updateLastActivityTime();
 
+    std::time_t getIdleTime() const { return std::time(nullptr) - _lastActivity; }
+
 private:
     /// Sends the .uno:Save command to LoKit.
     bool sendUnoSave(const bool dontSaveIfUnmodified);
@@ -343,6 +345,8 @@ private:
 
     int _debugRenderedTileCount;
 
+    std::time_t _lastActivity;
+
     static constexpr auto IdleSaveDurationMs = 30 * 1000;
     static constexpr auto AutoSaveDurationMs = 300 * 1000;
 };
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index b5b45bd..2eb77ae 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2045,6 +2045,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 #endif
 
     time_t last30SecCheck = time(nullptr);
+    time_t lastOneHourCheck = time(nullptr);
     int status = 0;
     while (!TerminationFlag && !SigUtil::isShuttingDown())
     {
@@ -2135,6 +2136,32 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
             }
             else
             {
+                // Every 15 minutes
+                if (time(nullptr) >= lastOneHourCheck + 900)
+                {
+                    // Bluntly close documents that have been idle over an hour. (By that time
+                    // loleaflet's greying-out has already also kicked in.)
+                    try
+                    {
+                        std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
+                        for (auto& pair : DocBrokers)
+                        {
+                            auto docLock = pair.second->getLock();
+                            if (pair.second->getIdleTime() >= 3600)
+                            {
+                                LOG_INF("Terminating idle document " + pair.second->getDocKey());
+                                pair.second->terminateChild(docLock);
+                            }
+                        }
+                    }
+                    catch (const std::exception& exc)
+                    {
+                        LOG_ERR("Exception: " << exc.what());
+                    }
+
+                    lastOneHourCheck = time(nullptr);
+                }
+
                 // Don't wait if we had been saving, which takes a while anyway.
                 std::this_thread::sleep_for(std::chrono::milliseconds(CHILD_REBALANCE_INTERVAL_MS));
             }


More information about the Libreoffice-commits mailing list