Fixed false asserts in cloud

This commit is contained in:
r.kuznetsov 2018-05-07 18:31:35 +03:00 committed by Daria Volvenkova
parent d0a762cbaa
commit 1f8e343a84

View file

@ -698,16 +698,17 @@ void Cloud::ScheduleUploadingTask(EntryPtr const & entry, uint32_t timeout,
{
std::string entryName;
std::string entryHash;
bool isInvalidToken;
{
std::lock_guard<std::mutex> lock(m_mutex);
#ifdef DEBUG
ASSERT(m_state == State::Enabled, ());
ASSERT(!m_accessToken.empty(), ());
ASSERT(m_uploadingStarted, ());
// Uploading has finished.
if (!m_uploadingStarted)
return;
ASSERT(entry->m_isOutdated, ());
#endif
entryName = entry->m_name;
entryHash = entry->m_hash;
isInvalidToken = m_accessToken.empty();
}
if (kServerUrl.empty())
@ -716,6 +717,13 @@ void Cloud::ScheduleUploadingTask(EntryPtr const & entry, uint32_t timeout,
return;
}
// Access token may become invalid between tasks.
if (isInvalidToken)
{
FinishUploading(SynchronizationResult::AuthError, "Access token is empty");
return;
}
// Prepare file to uploading.
auto const uploadedName = PrepareFileToUploading(entryName);
auto deleteAfterUploading = [uploadedName]() {
@ -818,15 +826,17 @@ void Cloud::CreateSnapshotTask(uint32_t timeout, uint32_t attemptIndex,
[this, timeout, attemptIndex, files = std::move(files),
handler = std::move(handler)]() mutable
{
#ifdef DEBUG
ASSERT(!files.empty(), ());
bool isInvalidToken;
{
// Uploading has finished.
std::lock_guard<std::mutex> lock(m_mutex);
ASSERT(m_state == State::Enabled, ());
ASSERT(!m_accessToken.empty(), ());
ASSERT(m_uploadingStarted, ());
ASSERT(!files.empty(), ());
if (!m_uploadingStarted)
return;
isInvalidToken = m_accessToken.empty();
}
#endif
if (kServerUrl.empty())
{
@ -834,6 +844,13 @@ void Cloud::CreateSnapshotTask(uint32_t timeout, uint32_t attemptIndex,
return;
}
// Access token may become invalid between tasks.
if (isInvalidToken)
{
FinishUploading(SynchronizationResult::AuthError, "Access token is empty");
return;
}
auto const result = CreateSnapshot(files);
if (result.m_status == RequestStatus::NetworkError)
{
@ -865,14 +882,15 @@ void Cloud::FinishSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
GetPlatform().RunDelayedTask(Platform::Thread::Network, seconds(timeout),
[this, timeout, attemptIndex]()
{
#ifdef DEBUG
bool isInvalidToken;
{
// Uploading has finished.
std::lock_guard<std::mutex> lock(m_mutex);
ASSERT(m_state == State::Enabled, ());
ASSERT(!m_accessToken.empty(), ());
ASSERT(m_uploadingStarted, ());
if (!m_uploadingStarted)
return;
isInvalidToken = m_accessToken.empty();
}
#endif
if (kServerUrl.empty())
{
@ -880,6 +898,13 @@ void Cloud::FinishSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
return;
}
// Access token may become invalid between tasks.
if (isInvalidToken)
{
FinishUploading(SynchronizationResult::AuthError, "Access token is empty");
return;
}
auto const result = FinishSnapshot();
if (result.m_status == RequestStatus::Ok)
{
@ -1201,14 +1226,15 @@ void Cloud::GetBestSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
GetPlatform().RunDelayedTask(Platform::Thread::Network, seconds(timeout),
[this, timeout, attemptIndex]()
{
#ifdef DEBUG
bool isInvalidToken;
{
// Restoring state may be changed between tasks.
std::lock_guard<std::mutex> lock(m_mutex);
ASSERT(m_state == State::Enabled, ());
ASSERT(!m_accessToken.empty(), ());
ASSERT_EQUAL(m_restoringState, RestoringState::Requested, ());
if (m_restoringState != RestoringState::Requested)
return;
isInvalidToken = m_accessToken.empty();
}
#endif
if (kServerUrl.empty())
{
@ -1216,6 +1242,13 @@ void Cloud::GetBestSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
return;
}
// Access token may become invalid between tasks.
if (isInvalidToken)
{
FinishRestoring(SynchronizationResult::AuthError, "Access token is empty");
return;
}
auto const result = GetBestSnapshot();
if (result.m_isMalformed)
{
@ -1270,11 +1303,11 @@ void Cloud::ProcessSuccessfulSnapshot(SnapshotResult const & result)
}
// Save snapshot data.
bool isInterrupted = false;
bool isInterrupted;
{
std::lock_guard<std::mutex> lock(m_mutex);
m_bestSnapshotData = result.m_response;
isInterrupted = m_restoringState != RestoringState::Requested;
isInterrupted = (m_restoringState != RestoringState::Requested);
}
if (!isInterrupted)
{