Skip to content

Commit

Permalink
Wait for download completion when downloading fresh FLX realm in clie…
Browse files Browse the repository at this point in the history
…nt reset (#5805)
  • Loading branch information
jbreams authored Sep 2, 2022
1 parent d6ef0c2 commit 07265cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* 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)).
* Fixed an exception "fcntl() with F_BARRIERFSYNC failed: Inappropriate ioctl for device" when running with MacOS on an exFAT drive. ([#5789](https://github.com/realm/realm-core/issues/5789) since 12.0.0)
* 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
Expand Down
26 changes: 23 additions & 3 deletions src/realm/object-store/sync/sync_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sync::SubscriptionSet::State> s) {
.then([=, weak_self = weak_from_this()](sync::SubscriptionSet::State) {
auto pf = util::make_promise_future<void>();
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();
Expand All @@ -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);
}
}
});
Expand Down

0 comments on commit 07265cb

Please sign in to comment.