[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

Michael Meeks michael.meeks at collabora.com
Fri Mar 10 18:00:03 UTC 2017


 net/Socket.hpp           |    5 ++-
 net/WebSocketHandler.hpp |    2 +
 wsd/DocumentBroker.cpp   |    1 
 wsd/DocumentBroker.hpp   |    1 
 wsd/LOOLWSD.cpp          |   64 ++++-------------------------------------------
 5 files changed, 13 insertions(+), 60 deletions(-)

New commits:
commit 160446fd235c3d1bf25413fea18c72f1e3487cbe
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Mar 10 17:58:51 2017 +0000

    Work on resurrecting dying DocumentBrokers if we can.
    
    The hope is that they will close lingering session sockets at the
    end and the client will re-connect.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index c5e5ece..9259d88 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -52,7 +52,9 @@ public:
 
     virtual ~Socket()
     {
-        //TODO: Should we shutdown here or up to the client?
+        // TODO: Should we shutdown here or up to the client?
+
+        LOG_TRC("#" << getFD() << " close socket.");
 
         // Doesn't block on sockets; no error handling needed.
         close(_fd);
@@ -551,6 +553,7 @@ public:
     virtual void shutdown() override
     {
         _shutdownSignalled = true;
+        LOG_TRC("#" << getFD() << ": shutdown signalled");
     }
 
     /// Perform the real shutdown.
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 5e987fb..7416586 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -97,6 +97,8 @@ public:
         if (socket == nullptr)
             return;
 
+        LOG_TRC("#" << socket->getFD() << " shutdown websocket.");
+
         const size_t len = statusMessage.size();
         std::vector<char> buf(2 + len);
         buf[0] = ((((int)statusCode) >> 8) & 0xff);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f50d9a3..1369ba5 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -751,6 +751,7 @@ size_t DocumentBroker::addSession(std::shared_ptr<ClientSession>& session)
     // document). It is safe to reset their values to their defaults whenever a new session is added.
     _lastEditableSession = false;
     _markToDestroy = false;
+    _stop = false;
 
     const auto id = session->getId();
     if (!_sessions.emplace(id, session).second)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 5594c70..b07b9b5 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -175,7 +175,6 @@ public:
         try
         {
             return _pid > 1 && _ws && kill(_pid, 0) == 0;
-// FIXME:                    !_ws->poll(Poco::Timespan(0), Poco::Net::Socket::SelectMode::SELECT_ERROR));
         }
         catch (const std::exception&)
         {
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 8d0a3a4e..7eafcdf 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1335,59 +1335,12 @@ static std::shared_ptr<DocumentBroker> findOrCreateDocBroker(WebSocketHandler& w
         // Get the DocumentBroker from the Cache.
         LOG_DBG("Found DocumentBroker with docKey [" << docKey << "].");
         docBroker = it->second;
-        if (docBroker->isMarkedToDestroy())
-        {
-            // Let the waiting happen in parallel to new requests.
-            docBrokersLock.unlock();
-
-            // If this document is going out, wait.
-            LOG_DBG("Document [" << docKey << "] is marked to destroy, waiting to reload.");
-
-            // FIXME: - easiest to send a fast message to the
-            //          client to wait & retry in a bit ...
-
-#if 0 // loolnb
-            bool timedOut = true;
-            for (size_t i = 0; i < COMMAND_TIMEOUT_MS / POLL_TIMEOUT_MS; ++i)
-            {
-
-                // FIXME: blocks !
-                std::this_thread::sleep_for(std::chrono::milliseconds(POLL_TIMEOUT_MS));
-
-                docBrokersLock.lock();
-                it = DocBrokers.find(docKey);
-                if (it == DocBrokers.end())
-                {
-                    // went away successfully
-                    docBroker.reset();
-                    docBrokersLock.unlock();
-                    timedOut = false;
-                    break;
-                }
-                else if (it->second && !it->second->isMarkedToDestroy())
-                {
-                    // was actually replaced by a real document
-                    docBroker = it->second;
-                    docBrokersLock.unlock();
-                    timedOut = false;
-                    break;
-                }
 
-                docBrokersLock.unlock();
-                if (TerminationFlag)
-                {
-                    LOG_ERR("Termination flag set. Not loading new session [" << id << "]");
-                    return nullptr;
-                }
-            }
-
-            if (timedOut)
-            {
-                // Still here, but marked to destroy. Proceed and hope to recover.
-                LOG_ERR("Timed out while waiting for document to unload before loading.");
-            }
-#endif
-        }
+        // Avoid notifying the client - either we catch and stop the
+        // destruction when we add the session, -or- the client
+        // re-connects.
+        if (docBroker->isMarkedToDestroy())
+            LOG_WRN("Associating with Document Broker with docKey [" << docKey << "] that is marked to be destroyed!");
     }
     else
     {
@@ -1454,12 +1407,7 @@ static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHand
         }
 
         if (docBroker->isMarkedToDestroy())
-        {
-            LOG_ERR("DocBroker is marked to destroy, can't add session.");
-            lock.unlock();
-            removeDocBrokerSession(docBroker);
-            return nullptr;
-        }
+            LOG_WRN("DocBroker is marked to destroy, attempting to add session anyway.");
 
         // Now we have a DocumentBroker and we're ready to process client commands.
         const std::string statusReady = "statusindicator: ready";


More information about the Libreoffice-commits mailing list