diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 8bfd559a8..9106a8c2c 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1575,21 +1575,17 @@ void DocumentBroker::checkAndUploadToStorage(const std::shared_ptrisCloseFrame()) - disconnectSessionInternal(session); - - // If marked to destroy, then this was the last session. - if (_docState.isMarkedToDestroy() || _sessions.empty()) + // If session is disconnected, remove. + LOG_TRC("Nothing to upload, disconnecting closed sessions"); + for (const auto& pair : _sessions) { - // Stop so we get cleaned up and removed. - LOG_DBG("Stopping after saving because " - << (_sessions.empty() ? "there are no active sessions left." - : "the document is marked to destroy")); - stop("unloading"); + if (pair.second->isCloseFrame() && !pair.second->inWaitDisconnected()) + { + LOG_TRC("Disconnecting session [" << pair.second->getName() << ']'); + disconnectSessionInternal(pair.second); + } } } } @@ -1960,6 +1956,15 @@ void DocumentBroker::handleUploadToStorageResponse(const StorageBase::UploadResu stop("unloading"); } + // After uploading, disconnect the sessions pending disconnection. + for (const auto& pair : _sessions) + { + if (pair.second->isCloseFrame() && !pair.second->inWaitDisconnected()) + { + disconnectSessionInternal(pair.second); + } + } + return; } else if (uploadResult.getResult() == StorageBase::UploadResult::Result::TOO_LARGE)