From d1e0b978d671d166589b2a7c63d3fb6275c6a75d Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Thu, 15 Sep 2016 16:14:59 +0200 Subject: [PATCH] bccu#2005 follow-up: If the document appearead in the meantime, finish early. --- loolwsd/LOOLWSD.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 91746f8dd..41d952d96 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 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.");