Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Fix bad_version when m_notifiers is empty (#424)
Browse files Browse the repository at this point in the history
* Fix bad_version when m_notifiers is empty

realm/realm-swift#4768
realm/realm-java#4369

When m_notifiers is empty, m_notifier_sg will be advanced to the latest.
But the skip_version might be behind. In this case, bad_version will be
throw when calling advance_to_final().

* Add a test which reproduces the problem
  • Loading branch information
beeender authored and tgoyne committed Mar 31, 2017
1 parent 7f80f8f commit 32de88f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/impl/realm_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ void RealmCoordinator::clean_up_dead_notifiers()
if (m_notifiers.empty() && m_notifier_sg) {
REALM_ASSERT_3(m_notifier_sg->get_transact_stage(), ==, SharedGroup::transact_Reading);
m_notifier_sg->end_read();
m_notifier_skip_version = {0, 0};
}
}
if (swap_remove(m_new_notifiers) && m_advancer_sg) {
Expand Down Expand Up @@ -693,6 +694,7 @@ void RealmCoordinator::run_async_notifiers()
lock.unlock();

if (skip_version.version) {
REALM_ASSERT(!notifiers.empty());
REALM_ASSERT(version >= skip_version);
IncrementalChangeInfo change_info(*m_notifier_sg, notifiers);
for (auto& notifier : notifiers)
Expand Down
21 changes: 21 additions & 0 deletions tests/results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,27 @@ TEST_CASE("notifications: skip") {
advance_and_notify(*r);
REQUIRE(calls1 == 2);
}

SECTION("removing skipped notifier before it gets the chance to run") {
advance_and_notify(*r);
REQUIRE(calls1 == 1);

// Set the skip version
make_local_change(token1);
// Advance the file to a version after the skip version
make_remote_change();
REQUIRE(calls1 == 1);

// Remove the skipped notifier and add an entirely new notifier, so that
// notifications need to run but the skip logic shouldn't be used
token1 = {};
results = {};
Results results2(r, table->where());
auto token2 = add_callback(results2, calls1, changes1);

advance_and_notify(*r);
REQUIRE(calls1 == 2);
}
}

#if REALM_PLATFORM_APPLE
Expand Down

0 comments on commit 32de88f

Please sign in to comment.