realm-swift: Migration to Realm 2.0.0 - terminating with uncaught exception of type realm::SharedGroup::BadVersion: std::exception

Going from RealmSwift 1.1.0 to Realm 2.0.0, with a clean install of our application, we are experiencing this crash :

libc++abi.dylib: terminating with uncaught exception of type realm::SharedGroup::BadVersion: std::exception

The code where it breaks is :

template <typename T>
std::unique_ptr<T> SharedGroup::import_from_handover(std::unique_ptr<SharedGroup::Handover<T>> handover)
{
    if (handover->version != get_version_of_current_transaction()) {
        **throw BadVersion();**
    }
    std::unique_ptr<T> result = move(handover->clone);
    result->apply_and_consume_patch(handover->patch, m_group);
    return result;
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 23 (8 by maintainers)

Most upvoted comments

We are still having this crash. Even with the latest commits on master.

It seems related to the realm not being refreshed when it should. We are using a lot of background queues and operation queues with a lot of write transaction in each operation queues. The issue seems related to the fact that the autorefresh is not working when no runloop is available.

We modified the core of our sync process to use a realm that is not auto-updating and calling refresh() manually. It seems that it helps but we are still seeing the issue (crash) at once in a while (way less but still).

Since we don’t really now when we need to call the refresh, we are adding it a bit everywhere: before and after write transactions. Will continue to add them to test.

Would love to have something done realm side instead of manually our side. Don’t know why it is not done automatically, it should imho.

Note: the same code did not make any issue with Realm 1.1.0 and under. But we had a lot of issues with realm files expanding beyond expected (that’s why we are compating the realm at launch to avoid crashes when mmaping). Both issues are maybe related. Would love to see Realm handle write transaction in background queues safer.

+1 It happens randomly

Here are some info about the issue.

The crash is only occurring on devices where big synchronisation is done. Meaning a lot of objects are created, accessed (for processing), updated,… Mostly operations added on NSOperationQueues with .UserInitiated or .Utility QOS.

Here is the full stack trace: https://www.dropbox.com/s/shpy6x51dp92blr/realm2.0.0Stack.png?dl=0 Maybe it will help solve the issue.

We tried to reproduce the crash in other projects and in a new project but since we don’t know if the problem is the model, the read/write, the amount of operations,… we are a bit in the dark. Can’t share the code of the project where it happens unfortunately.

Note, we also have, in the same project this issue: https://github.com/realm/realm-cocoa/issues/4143 but when a migration between 1.1.0 to 2.0.0 occurs. Don’t know if it has an impact or not.