From 768958edcd3b407e57177e165271cb3397a2092b Mon Sep 17 00:00:00 2001 From: Jonathan Reams Date: Wed, 31 Aug 2022 18:04:13 -0400 Subject: [PATCH 1/2] Wait for download completion when downloading fresh FLX realm in client reset --- src/realm/object-store/sync/sync_session.cpp | 26 +++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/realm/object-store/sync/sync_session.cpp b/src/realm/object-store/sync/sync_session.cpp index a12003d637c..279aee69b9b 100644 --- a/src/realm/object-store/sync/sync_session.cpp +++ b/src/realm/object-store/sync/sync_session.cpp @@ -392,7 +392,28 @@ void SyncSession::download_fresh_realm(sync::ProtocolErrorInfo::Action server_re std::move(fresh_mut_sub) .commit() .get_state_change_notification(sync::SubscriptionSet::State::Complete) - .get_async([=, weak_self = weak_from_this()](StatusWith s) { + .then([=, weak_self = weak_from_this()](sync::SubscriptionSet::State) { + auto pf = util::make_promise_future(); + sync_session->wait_for_download_completion([=, promise = std::move(pf.promise)]( + std::error_code ec) mutable { + auto strong_self = weak_self.lock(); + if (!strong_self) { + return promise.set_error({ErrorCodes::RuntimeError, + "SyncSession was destroyed before download could be completed"}); + } + + if (ec) { + return promise.set_error( + {ErrorCodes::RuntimeError, + util::format("Error waiting for download completion for fresh realm (code: %1): %2", + ec.value(), ec.message())}); + } + + promise.emplace_value(); + }); + return std::move(pf.future); + }) + .get_async([=, weak_self = weak_from_this()](Status s) { // Keep the sync session alive while it's downloading, but then close // it immediately sync_session->close(); @@ -401,8 +422,7 @@ void SyncSession::download_fresh_realm(sync::ProtocolErrorInfo::Action server_re strong_self->handle_fresh_realm_downloaded(db, none, server_requests_action); } else { - strong_self->handle_fresh_realm_downloaded(nullptr, s.get_status().reason(), - server_requests_action); + strong_self->handle_fresh_realm_downloaded(nullptr, s.reason(), server_requests_action); } } }); From 3938a09818142799507a546377e30896ce048804 Mon Sep 17 00:00:00 2001 From: Jonathan Reams Date: Fri, 2 Sep 2022 14:11:05 -0400 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 082bd689299..12c37e27302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * Fix sorting order for `realm_query_find_first` in the C API.([#5720](https://github.com/realm/realm-core/issues/5720)) * Upload completion callbacks may have called before the download message that completed them was fully integrated. ([#4865](https://github.com/realm/realm-core/issues/4865)). * Syncing of a Decimal128 with big significand could result in a crash. ([#5728](https://github.com/realm/realm-core/issues/5728)) +* Recovery/discardLocal client reset modes will now wait for FLX sync realms to be fully synchronized before beginning recovery operations ([#5705](https://github.com/realm/realm-core/issues/5705)) ### Breaking changes