From d9a3a4213796692c4a15b0cc80373477ca442bef Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Mon, 31 Jan 2022 21:27:07 -0500 Subject: [PATCH] wsd: wait for the modified flag before giving up By waiting at most 2 seconds, we improve the chances of getting the ModifiedStatus=false before we termiante the document. This minimizes the noise of warning of potentially lost data on exit and similarly reduces the test failures, which test for clear termination. Change-Id: I284693d1cdd91b1224581fdc29e6e5438ab4c0b2 Signed-off-by: Ashod Nakashian --- wsd/DocumentBroker.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index ed6d2ded2..7817e47e2 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1832,7 +1832,7 @@ bool DocumentBroker::autoSave(const bool force, const bool dontSaveIfUnmodified) void DocumentBroker::autoSaveAndStop(const std::string& reason) { - LOG_TRC("autoSaveAndStop for docKey [" << getDocKey() << ']'); + LOG_TRC("autoSaveAndStop for docKey [" << getDocKey() << "]: " << reason); if (_saveManager.isSaving() || isAsyncUploading()) { @@ -1851,6 +1851,22 @@ void DocumentBroker::autoSaveAndStop(const std::string& reason) _saveManager.lastSaveRequestTime() < _saveManager.lastSaveResponseTime() && _saveManager.lastSaveSuccessful()) { + // We can stop, but the modified flag is set. Delayed ModifiedStatus? + if (isModified()) + { + if (_saveManager.timeSinceLastSaveResponse() < std::chrono::seconds(2)) + { + LOG_INF("Can stop " << reason << " DocumentBroker for docKey [" << getDocKey() + << "] but will wait for isModified to clear."); + return; + } + else + { + LOG_WRN("Will stop " << reason << " DocumentBroker for docKey [" << getDocKey() + << "] even with isModified, which is not clearing."); + } + } + // Nothing to upload and last save was successful; stop. canStop = true; LOG_TRC("autoSaveAndStop for docKey ["