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 <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2022-01-31 21:27:07 -05:00 committed by Ashod Nakashian
parent 35b3b87704
commit d9a3a42137

View file

@ -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 ["