[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Sep 20 03:25:39 UTC 2016


 loolwsd/LOOLKit.cpp |   25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

New commits:
commit 23ef612970ff5e90ffc8da63f503170aef9a56be
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Sep 17 10:04:28 2016 -0400

    loolwsd: ensure that the connection thread is running
    
    If the connection thread is not running when loading a
    document, the callback will drop events. This can happen
    when the thread is too slow to spawn, but we return from
    the createSession function and process client messages.
    
    This should solve the race where we lose notifications of
    other views when a new view is created.
    
    Change-Id: Ia79739889b2f01fbb374d48eb33620084f4ed1c1
    Reviewed-on: https://gerrit.libreoffice.org/29063
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 252cfb3..51c33f3 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -28,6 +28,7 @@
 #include <memory>
 #include <sstream>
 #include <thread>
+#include <thread>
 
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitInit.h>
@@ -279,6 +280,16 @@ public:
     void start()
     {
         _thread.start(*this);
+
+        // Busy-wait until we run.
+        // This is important to make sure we can process
+        // callbacks, which if we're late to start will
+        // be dropped. No need for async notification here.
+        constexpr auto delay = COMMAND_TIMEOUT_MS / 20;
+        for (auto i = 0; i < 20 && !isRunning(); ++i)
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(delay));
+        }
     }
 
     bool isRunning()
@@ -871,15 +882,23 @@ private:
         bool isFound = false;
         for (auto& it : pDescr->Doc->_connections)
         {
-            if (it.second->isRunning())
+            auto session = it.second->getSession();
+            if (session && session->getViewId() == pDescr->ViewId)
             {
-                auto session = it.second->getSession();
-                if (session && session->getViewId() == pDescr->ViewId)
+                if (it.second->isRunning())
                 {
                     isFound = true;
                     auto pNotif = new CallbackNotification(session, nType, payload);
                     pDescr->Doc->_callbackQueue.enqueueNotification(pNotif);
                 }
+                else
+                {
+                    Log::error() << "Connection thread for session " << it.second->getSessionId() << " for view "
+                                 << pDescr->ViewId << " is not running. Dropping [" << LOKitHelper::kitCallbackTypeToString(nType)
+                                 << "] payload [" << payload << "]." << Log::end;
+                }
+
+                break;
             }
         }
 


More information about the Libreoffice-commits mailing list