bccu#2005 follow-up: If the document appearead in the meantime, finish early.

This commit is contained in:
Jan Holesovsky 2016-09-15 16:14:59 +02:00
parent 912281bd20
commit d1e0b978d6

View file

@ -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<std::mutex> 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.");