[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp
Ashod Nakashian (via logerrit)
logerrit at kemper.freedesktop.org
Mon Nov 4 08:36:29 UTC 2019
wsd/DocumentBroker.cpp | 2 -
wsd/LOOLWSD.cpp | 64 +++++++++++++++++++++++++++++++------------------
2 files changed, 42 insertions(+), 24 deletions(-)
New commits:
commit f18cd4c45855c84659af59afad8b936f5c087a0e
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Sun Nov 3 15:03:11 2019 -0500
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Nov 4 09:36:24 2019 +0100
wsd: improved shutdown cleanup
(cherry picked from commit 5eb58d4e13ed43156115d25482dffa96d7768bfe)
Change-Id: Ibdb822575c376af6065080070bf6b89c240ce67b
Reviewed-on: https://gerrit.libreoffice.org/81977
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index d3b0c654f..754844e89 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -485,7 +485,7 @@ void DocumentBroker::joinThread()
void DocumentBroker::stop(const std::string& reason)
{
- LOG_DBG("Closing DocumentBroker for docKey [" << _docKey << "] with reason: " << reason);
+ LOG_DBG("Stopping DocumentBroker for docKey [" << _docKey << "] with reason: " << reason);
_closeReason = reason; // used later in the polling loop
_stop = true;
_poll->wakeup();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index f6d5132dc..0a66ac719 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3488,8 +3488,8 @@ int LOOLWSD::innerMain()
#if ENABLE_DEBUG
if (careerSpanMs > 0 && timeSinceStartMs > careerSpanMs)
{
- LOG_INF(timeSinceStartMs << " milliseconds gone, finishing as requested.");
- break;
+ LOG_INF(timeSinceStartMs << " milliseconds gone, finishing as requested. Setting ShutdownRequestFlag.");
+ SigUtil::requestShutdown();
}
#endif
}
@@ -3502,36 +3502,54 @@ int LOOLWSD::innerMain()
srv.stop();
// atexit handlers tend to free Admin before Documents
- LOG_INF("Cleaning up lingering documents.");
- if (SigUtil::getShutdownRequestFlag() || SigUtil::getTerminationFlag())
+ LOG_INF("Exiting. Cleaning up lingering documents.");
+ if (!SigUtil::getShutdownRequestFlag())
{
- // Don't stop the DocBroker, they will exit.
- const size_t sleepMs = 300;
- const size_t count = std::max<size_t>(COMMAND_TIMEOUT_MS, 2000) / sleepMs;
- for (size_t i = 0; i < count; ++i)
- {
- std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
- cleanupDocBrokers();
- if (DocBrokers.empty())
- break;
- docBrokersLock.unlock();
-
- // Give them time to save and cleanup.
- std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
- }
+ // This shouldn't happen, but it's fail safe to always cleanup properly.
+ LOG_WRN("Exiting WSD without ShutdownRequestFlag. Setting it now.");
+ SigUtil::requestShutdown();
}
- else
+
+ // Don't stop the DocBroker, they will exit.
+ constexpr size_t sleepMs = 500;
+ constexpr size_t count = (COMMAND_TIMEOUT_MS * 4) / sleepMs;
+ for (size_t i = 0; i < count; ++i)
{
- // Stop and join.
- for (auto& docBrokerIt : DocBrokers)
- docBrokerIt.second->joinThread();
+ std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
+ if (DocBrokers.empty())
+ break;
+
+ LOG_DBG("Waiting for " << DocBrokers.size() << " documents to stop.");
+ cleanupDocBrokers();
+ docBrokersLock.unlock();
+
+ // Give them time to save and cleanup.
+ std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
}
// Disable thread checking - we'll now cleanup lots of things if we can
Socket::InhibitThreadChecks = true;
SocketPoll::InhibitThreadChecks = true;
- DocBrokers.clear();
+ // Wait for the DocumentBrokers. They must be saving/uploading now.
+ // Do not stop them! Otherwise they might not save/upload the document.
+ // We block until they finish, or the service stopping times out.
+ {
+ std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
+ for (auto& docBrokerIt : DocBrokers)
+ {
+ std::shared_ptr<DocumentBroker> docBroker = docBrokerIt.second;
+ if (docBroker && docBroker->isAlive())
+ {
+ LOG_DBG("Joining docBroker [" << docBrokerIt.first << "].");
+ docBroker->joinThread();
+ }
+ }
+
+ // Now should be safe to destroy what's left.
+ cleanupDocBrokers();
+ DocBrokers.clear();
+ }
#if !defined(KIT_IN_PROCESS) && !MOBILEAPP
// Terminate child processes
More information about the Libreoffice-commits
mailing list