loolwsd/LOOLWSD.cpp | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-)
New commits: commit a6f70aad79b938cb909ba60a3e9a75b2cfc69b22 Author: Jan Holesovsky <ke...@collabora.com> Date: Thu Sep 15 17:48:01 2016 +0200 bccu#2005 follow-up: Another place where we need the dummy document broker. I think this is another potential race condition... diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index a2e327d..57b996b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -593,6 +593,11 @@ private: { // went away successfully docBroker.reset(); + Log::debug("Inserting a dummy DocumentBroker for docKey [" + docKey + "] temporarily after the other instance is gone."); + + std::shared_ptr<DocumentBroker> tempBroker = std::make_shared<DocumentBroker>(); + docBrokers.emplace(docKey, tempBroker); + timedOut = false; break; } commit 10392f9ba6c1dc172e77713449ec97f7ea013177 Author: Jan Holesovsky <ke...@collabora.com> Date: Thu Sep 15 17:22:28 2016 +0200 Decrease the level of indentation. diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 41d952d..a2e327d 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -576,42 +576,40 @@ private: } } - if (docBroker) + if (docBroker && docBroker->isMarkedToDestroy()) { // If this document is going out, wait. - if (docBroker->isMarkedToDestroy()) + Log::debug("Document [" + docKey + "] is marked to destroy, waiting to reload."); + + const auto timeout = POLL_TIMEOUT_MS / 2; + bool timedOut = true; + for (size_t i = 0; i < COMMAND_TIMEOUT_MS / timeout; ++i) { - Log::debug("Document [" + docKey + "] is marked to destroy, waiting to reload."); - const auto timeout = POLL_TIMEOUT_MS / 2; - bool timedOut = true; - for (size_t i = 0; i < COMMAND_TIMEOUT_MS / timeout; ++i) - { - std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); + std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); - std::unique_lock<std::mutex> lock(docBrokersMutex); - auto it = docBrokers.find(docKey); - if (it == docBrokers.end()) - { - // went away successfully - docBroker.reset(); - timedOut = false; - break; - } - else if (it->second && !it->second->isMarkedToDestroy()) - { - // was actually replaced by a real document - docBroker = it->second; - timedOut = false; - break; - } + std::unique_lock<std::mutex> lock(docBrokersMutex); + auto it = docBrokers.find(docKey); + if (it == docBrokers.end()) + { + // went away successfully + docBroker.reset(); + timedOut = false; + break; } - - if (timedOut) + else if (it->second && !it->second->isMarkedToDestroy()) { - // Still here, but marked to destroy. Proceed and hope to recover. - Log::error("Timed out while waiting for document to unload before loading."); + // was actually replaced by a real document + docBroker = it->second; + timedOut = false; + break; } } + + if (timedOut) + { + // Still here, but marked to destroy. Proceed and hope to recover. + Log::error("Timed out while waiting for document to unload before loading."); + } } bool newDoc = false; commit d1e0b978d671d166589b2a7c63d3fb6275c6a75d Author: Jan Holesovsky <ke...@collabora.com> Date: Thu Sep 15 16:14:59 2016 +0200 bccu#2005 follow-up: If the document appearead in the meantime, finish early. diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 91746f8..41d952d 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -583,18 +583,30 @@ private: { Log::debug("Document [" + docKey + "] is marked to destroy, waiting to reload."); const auto timeout = POLL_TIMEOUT_MS / 2; + bool timedOut = true; for (size_t i = 0; i < COMMAND_TIMEOUT_MS / timeout; ++i) { std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); + std::unique_lock<std::mutex> lock(docBrokersMutex); - if (docBrokers.find(docKey) == docBrokers.end()) + auto it = docBrokers.find(docKey); + if (it == docBrokers.end()) { + // went away successfully docBroker.reset(); + timedOut = false; + break; + } + else if (it->second && !it->second->isMarkedToDestroy()) + { + // was actually replaced by a real document + docBroker = it->second; + timedOut = false; break; } } - if (docBroker) + if (timedOut) { // Still here, but marked to destroy. Proceed and hope to recover. Log::error("Timed out while waiting for document to unload before loading."); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits