realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.27k stars 2.14k forks source link

EXC_BAD_ACCESS when RLMArrayLinkView is destroyed on different thread than it was allocated on #3307

Closed Legoless closed 8 years ago

Legoless commented 8 years ago

Goals

I have a NSOperation that should update a relation in the default Realm that the application uses. The update is done with 2 primary keys and target objects. The Realm snapshot needs to be at the latest update, before the operation is executed. Operations are executed on a background NSOperationQueue on a single thread (maxConcurrentOperationCount = 1), only one operation is allowed to be executed at the same time, so there are no race conditions.

Expected Results

The error does not occur always, but it is common enough to be easily replicated. A new instance of Realm is created for every operation. Autorefresh is disabled and the Realm is forcefully refreshed with refresh() call, to be at the latest update. The code works in general, but crashes at the refresh call occasionally. If refresh is not called Realm will not be at the latest update.

Actual Results

The code crashes with EXC_BAD_ACCESS after refresh() call. The stack trace shows that the crash happens somewhere inside group.hpp file, at line 1197:

static void advance_transact(Group& group, ref_type new_top_ref, size_t new_file_size,
                                 _impl::NoCopyInputStream& in)
    {
        group.advance_transact(new_top_ref, new_file_size, in); // Throws
    }

The crash usually happens at this line. The stack trace is below:

* thread #5: tid = 0x4521f9, 0x000000010b459037 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 311, queue = 'com.MyApp.database :: NSOperation 0x7f9972a51100 (QOS: USER_INITIATED)', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
  * frame #0: 0x000000010b459037 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 311
    frame #1: 0x000000010b4e7388 Realm`realm::Table::refresh_column_accessors(unsigned long) + 632
    frame #2: 0x000000010b4fe15a Realm`realm::Table::refresh_accessor_tree() + 666
    frame #3: 0x000000010b472e48 Realm`realm::Group::advance_transact(unsigned long, unsigned long, realm::_impl::NoCopyInputStream&) + 600
    frame #4: 0x000000010b1e344d Realm`realm::_impl::GroupFriend::advance_transact(group=0x00007f99750dbc00, new_top_ref=252536, new_file_size=458752, in=0x0000700000198cf8) + 45 at group.hpp:1197
    frame #5: 0x000000010b377acc Realm`void realm::SharedGroup::advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007f99750dbc00, history=0x00007f997253f578, observer=0x00007000001993d0, version=(version = 0, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 1052 at group_shared.hpp:933
    frame #6: 0x000000010b3776a5 Realm`void realm::_impl::SharedGroupFriend::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007f99750dbc00, hist=0x00007f997253f578, obs=0x00007000001993d0, ver=(version = 0, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 69 at group_shared.hpp:1093
    frame #7: 0x000000010b377655 Realm`void realm::LangBindHelper::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007f99750dbc00, history=0x00007f997253f578, observer=0x00007000001993d0, version=(version = 0, index = 0))::TransactLogValidator&&, realm::SharedGroup::VersionID) + 69 at lang_bind_helper.hpp:362
    frame #8: 0x000000010b377550 Realm`auto realm::_impl::transaction::advance(this=0x00007000001993b8, args=0x00007000001993d0)::$_0::operator()<(anonymous namespace)::TransactLogValidator&>((anonymous namespace)::TransactLogValidator&&&) const + 80 at transact_log_handler.cpp:437
    frame #9: 0x000000010b37716c Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007000001993d0, context=0x00007f9972d7bbf0, sg=0x00007f99750dbc00, func=0x00007000001993b8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::ClientHistory&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 1132 at transact_log_handler.cpp:222
    frame #10: 0x000000010b3768be Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007000001993d0, context=0x00007f9972d7bbf0, sg=0x00007f99750dbc00, func=0x00007000001993b8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::ClientHistory&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 62 at transact_log_handler.cpp:204
    frame #11: 0x000000010b37686a Realm`realm::_impl::transaction::advance(sg=0x00007f99750dbc00, history=0x00007f997253f530, delegate=0x00007f9972d7bbf0, version=(version = 0, index = 0)) + 106 at transact_log_handler.cpp:436
    frame #12: 0x000000010b370daa Realm`realm::Realm::refresh(this=0x00007f9972d68e40) + 362 at shared_realm.cpp:407
    frame #13: 0x000000010b341bee Realm`-[RLMRealm refresh](self=0x00007f9972d60f40, _cmd="refresh") + 46 at RLMRealm.mm:595
    frame #14: 0x000000010b7fb42d RealmSwift`RealmSwift.Realm.refresh (self=0x00007f99727a6900)() -> Swift.Bool + 45 at Realm.swift:526
    frame #15: 0x000000010a73c070 MyApp`MyApp.MyAppRelationOperation.realm.getter : RealmSwift.Realm(self=0x00007f9972a51100) + 880 at MyAppRelationOperation.swift:24
    frame #16: 0x000000010a73c42c MyApp`MyApp.MyAppRelationOperation.main (self=0x00007f9972a51100)() -> () + 44 at MyAppRelationOperation.swift:43
    frame #17: 0x000000010a73d6f2 MyApp`@objc MyApp.MyAppRelationOperation.main (MyApp.MyAppRelationOperation)() -> () + 34 at MyAppRelationOperation.swift:0
    frame #18: 0x000000010d094f8a Foundation`-[__NSOperationInternal _start:] + 646
    frame #19: 0x000000010d094b9b Foundation`__NSOQSchedule_f + 194
    frame #20: 0x000000010e94649b libdispatch.dylib`_dispatch_client_callout + 8
    frame #21: 0x000000010e92c8ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #22: 0x000000010e92be0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #23: 0x000000010e92ea56 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #24: 0x000000010e92e4c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #25: 0x000000010ec7e68f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #26: 0x000000010ec7c365 libsystem_pthread.dylib`start_wqthread + 13

Steps to Reproduce

  1. Create a serial NSOperationQueue.
  2. Create many operations on the queue that create / update objects.
  3. Create many RelationOperation operations (sample code provided below).
  4. Run the code multiple times until crash happens.

    Code Sample

This is the code for a NSOperation that triggers the crash (code was simplified and stripped of irrelevant situations, since the crash happens on the beginning):

import Foundation
import RealmSwift

class RelationOperation : NSOperation {

    // Database reference
    private var realmRef : Realm?

    var sourceClassName = ""
    var sourceKeyValue = ""
    var targetClassName = ""
    var targetKeyValue = ""

    var realm : Realm {
        get {
            if realmRef == nil {
                realmRef = try! Realm()
                realmRef!.autorefresh = false
            }

            realmRef!.refresh() // This is the line that triggers the crash, the first time Realm() is created.

            return realmRef!
        }
        set {
            realmRef = newValue
        }
    }
    override func main () {
        var source = realm.dynamicObjectForPrimaryKey(sourceClassName, key:sourceKeyValue) // This line triggers the getter and causes the crash.
        var target = realm.dynamicObjectForPrimaryKey(targetClassName, key:targetKeyValue)
    }
}

Version of Realm and Tooling

I'm using latest RealmSwift version 0.98.3, along with the latest Xcode in the Mac App Store (7.2.1 7C1002). Realm is installed with CocoaPods version 0.39.0 and uses Dynamic Frameworks, because it is a Swift project.

Thanks a lot for help, but I really don't know what the issue is here.

jpsim commented 8 years ago

We made some fixes that touched this part of the code recently in our core library. Could you please try your code by pointing to the master branch in your Podfile?

pod 'Realm', :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master'
pod 'RealmSwift', :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master'

Thanks!

Legoless commented 8 years ago

Thanks @jpsim, I tried the version on master and was not able to reproduce the issue so far (not saying it is fixed completely, but at least it is not that common anymore). I have some more information about it though. There was another operation running before the one I pasted code, and that one did not have autorefresh property set to false. So the issue is definitely connected with refreshing the instances, especially the autorefresh. It looks like something is not cleaned up correctly, but this could already be fixed.

Legoless commented 8 years ago

This is still an issue, however now it crashes on another place (still EXC_BAD_ACCESS):

* thread #5: tid = 0x161f00, 0x00000001071d00eb Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 299, queue = 'com.MyApp.database :: NSOperation 0x7faae9f38b40 (QOS: USER_INITIATED)', stop reason = EXC_BAD_ACCESS (code=1, address=0x60)
    frame #0: 0x00000001071d00eb Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 299
    frame #1: 0x000000010725f738 Realm`realm::Table::refresh_column_accessors(unsigned long) + 632
    frame #2: 0x0000000107276b0a Realm`realm::Table::refresh_accessor_tree() + 666
    frame #3: 0x00000001071ea6e8 Realm`realm::Group::advance_transact(unsigned long, unsigned long, realm::_impl::NoCopyInputStream&) + 600
  * frame #4: 0x00000001070eee25 Realm`bool realm::SharedGroup::do_advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007faaea95b200, observer=0x00007000001993f8, version_id=(version = 18446744073709551615, index = 0), hist=0x00007faaee828658)::TransactLogValidator*, realm::SharedGroup::VersionID, realm::_impl::History&) + 725 at group_shared.hpp:1060
    frame #5: 0x00000001070eeb32 Realm`void realm::SharedGroup::advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007faaea95b200, observer=0x00007000001993f8, version_id=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 402 at group_shared.hpp:930
    frame #6: 0x00000001070ee98b Realm`void realm::_impl::SharedGroupFriend::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007faaea95b200, obs=0x00007000001993f8, ver=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 59 at group_shared.hpp:1097
    frame #7: 0x00000001070ee93b Realm`void realm::LangBindHelper::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007faaea95b200, observer=0x00007000001993f8, version=(version = 18446744073709551615, index = 0))::TransactLogValidator&&, realm::SharedGroup::VersionID) + 59 at lang_bind_helper.hpp:352
    frame #8: 0x00000001070ee865 Realm`auto realm::_impl::transaction::advance(this=0x00007000001993e8, args=0x00007000001993f8)::$_0::operator()<(anonymous namespace)::TransactLogValidator&>((anonymous namespace)::TransactLogValidator&&&) const + 69 at transact_log_handler.cpp:438
    frame #9: 0x00000001070ee48c Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007000001993f8, context=0x00007faaee84afa0, sg=0x00007faaea95b200, func=0x00007000001993e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 1132 at transact_log_handler.cpp:222
    frame #10: 0x00000001070edbfe Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007000001993f8, context=0x00007faaee84afa0, sg=0x00007faaea95b200, func=0x00007000001993e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 62 at transact_log_handler.cpp:204
    frame #11: 0x00000001070edbaa Realm`realm::_impl::transaction::advance(sg=0x00007faaea95b200, context=0x00007faaee84afa0, version=(version = 18446744073709551615, index = 0)) + 90 at transact_log_handler.cpp:437
    frame #12: 0x00000001070e812a Realm`realm::Realm::refresh(this=0x00007faaee849bf0) + 266 at shared_realm.cpp:409
    frame #13: 0x00000001070b908e Realm`-[RLMRealm refresh](self=0x00007faaee846cf0, _cmd="refresh") + 46 at RLMRealm.mm:595
    frame #14: 0x000000010757642d RealmSwift`RealmSwift.Realm.refresh (self=0x00007faaee901fa0)() -> Swift.Bool + 45 at Realm.swift:526
    frame #15: 0x0000000106489e70 MyApp`MyApp.MyAppRelationOperation.realm.getter : RealmSwift.Realm(self=0x00007faae9f38b40) + 896 at MyAppRelationOperation.swift:24
    frame #16: 0x000000010648a22c MyApp`MyApp.MyAppRelationOperation.main (self=0x00007faae9f38b40)() -> () + 44 at MyAppRelationOperation.swift:43
    frame #17: 0x000000010648b4f2 MyApp`@objc MyApp.MyAppRelationOperation.main (MyApp.MyAppRelationOperation)() -> () + 34 at MyAppRelationOperation.swift:0
    frame #18: 0x0000000108e0ff8a Foundation`-[__NSOperationInternal _start:] + 646
    frame #19: 0x0000000108e0fb9b Foundation`__NSOQSchedule_f + 194
    frame #20: 0x000000010a6c149b libdispatch.dylib`_dispatch_client_callout + 8
    frame #21: 0x000000010a6a78ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #22: 0x000000010a6a6e0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #23: 0x000000010a6a9a56 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #24: 0x000000010a6a94c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #25: 0x000000010a9f968f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #26: 0x000000010a9f7365 libsystem_pthread.dylib`start_wqthread + 13

The crash is in the file group_shared.hpp on line 1060:

{
    version_type old_version = m_read_lock.m_version;
    version_type new_version = new_read_lock.m_version;
    ref_type new_top_ref = new_read_lock.m_top_ref;
    size_t new_file_size = new_read_lock.m_file_size;
    _impl::ChangesetInputStream in(hist, old_version, new_version);
    m_group.advance_transact(new_top_ref, new_file_size, in); // Crash is here.
}

Crash is triggered by refresh again. This crash is more uncommon than previous one.

jpsim commented 8 years ago

I've tried to reproduce the assertion you're seeing but haven't been able to yet, by running the following sample app about ~10 times in the iOS Simulator:

import UIKit
import RealmSwift

class ModelA: Object {
    dynamic var pk = 0
    override class func primaryKey() -> String? {
        return "pk"
    }
}

class ModelB: Object {
    dynamic var pk = 0
    override class func primaryKey() -> String? {
        return "pk"
    }
}

class RelationOperation: NSOperation {

    // Database reference
    private var realmRef: Realm!

    var sourceClassName = ModelA.className()
    var sourceKeyValue = 0
    var targetClassName = ModelB.className()
    var targetKeyValue = 0

    var realm: Realm {
        get {
            if realmRef == nil {
                realmRef = try! Realm()
                realmRef.autorefresh = false
            }

            realmRef.refresh() // This is the line that triggers the crash, the first time Realm() is created.

            return realmRef
        }
        set {
            realmRef = newValue
        }
    }

    override func main () {
        let source = realm.dynamicObjectForPrimaryKey(sourceClassName, key: sourceKeyValue) // This line triggers the getter and causes the crash.
        print(source)
        let target = realm.dynamicObjectForPrimaryKey(targetClassName, key: targetKeyValue)
        print(target)
    }
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var operations = [RelationOperation]()
    var queue: NSOperationQueue = {
        let queue = NSOperationQueue()
        queue.maxConcurrentOperationCount = 1
        return queue
    }()

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        do {
            try NSFileManager.defaultManager().removeItemAtPath(Realm.Configuration.defaultConfiguration.path!)
        } catch {}

        let realm = try! Realm()
        try! realm.write { realm.add(ModelA()); realm.add(ModelB()) }

        for _ in 0..<10_000 {
            queue.addOperation(RelationOperation())
        }
        return true
    }
}

Could you please either let me know if I'm missing something important in my repro case attempt, or alternatively send us a full Xcode project that compiles and triggers the assertion? Thanks!

Legoless commented 8 years ago

After the latest update this bug is a lot harder to reproduce. It's a bit hard to share the code, as it is a private project. Anyhow, I've updated the code and created a sample project that attempts to reproduce the issue (still cannot reproduce it in isolation).. Of course the real project has a lot more objects and a lot more data, so the situation is certainly different and is doing other work at the same time as well. I'll try some more things, but you can look at the project anyway. The following crash shows that it is connected to the linked list, which is what relations are updating.

One more crash in a different place (column_linklist.hpp):

inline void LinkListColumn::do_discard_child_accessors() noexcept
{
    discard_child_accessors(); // Crash is here, line 217
}
* thread #11: tid = 0xc5b6e, 0x000000010253e55a Realm`realm::LinkListColumn::discard_child_accessors() + 106, queue = 'com.apple.root.user-initiated-qos', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
    frame #0: 0x000000010253e55a Realm`realm::LinkListColumn::discard_child_accessors() + 106
  * frame #1: 0x000000010227be65 Realm`realm::LinkListColumn::do_discard_child_accessors(this=0x00007f7fd057be60) + 21 at column_linklist.hpp:217
    frame #2: 0x00000001025d4131 Realm`realm::Table::detach() + 193
    frame #3: 0x0000000102556bf0 Realm`realm::Group::detach() + 64
    frame #4: 0x0000000102560e84 Realm`realm::SharedGroup::end_read() + 68
    frame #5: 0x0000000102560605 Realm`realm::SharedGroup::close() + 69
    frame #6: 0x0000000102560f6e Realm`realm::SharedGroup::~SharedGroup() + 14
    frame #7: 0x0000000102457574 Realm`realm::Realm::~Realm() [inlined] std::__1::default_delete<realm::SharedGroup>::operator(this=0x00007f7fd0521998, __ptr=0x00007f7fd08de200)(realm::SharedGroup*) const + 39 at memory:2459
    frame #8: 0x000000010245754d Realm`realm::Realm::~Realm() [inlined] std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> >::reset(this=0x00007f7fd0521998, __p=0x0000000000000000) + 138 at memory:2658
    frame #9: 0x00000001024574c3 Realm`realm::Realm::~Realm() [inlined] std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> >::~unique_ptr(this=0x00007f7fd0521998) + 25 at memory:2626
    frame #10: 0x00000001024574aa Realm`realm::Realm::~Realm() [inlined] std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> >::~unique_ptr(this=0x00007f7fd0521998) + 14 at memory:2626
    frame #11: 0x000000010245749c Realm`realm::Realm::~Realm(this=0x00007f7fd05218f0) + 1900 at shared_realm.cpp:171
    frame #12: 0x00000001024576a5 Realm`realm::Realm::~Realm(this=0x00007f7fd05218f0) + 21 at shared_realm.cpp:167
    frame #13: 0x00000001022d667c Realm`std::__1::__shared_ptr_emplace<realm::Realm, std::__1::allocator<realm::Realm> >::__on_zero_shared(this=0x00007f7fd05218d0) + 44 at memory:3770
    frame #14: 0x0000000101c80dea libc++.1.dylib`std::__1::__shared_weak_count::__release_shared() + 44
    frame #15: 0x000000010228e8bf Realm`std::__1::shared_ptr<realm::Realm>::~shared_ptr(this=0x00007f7fd0526978) + 47 at memory:4490
    frame #16: 0x00000001022794d5 Realm`std::__1::shared_ptr<realm::Realm>::~shared_ptr(this=0x00007f7fd0526978) + 21 at memory:4488
    frame #17: 0x000000010242c9de Realm`-[RLMRealm .cxx_destruct](self=0x00007f7fd0526970, _cmd=".cxx_destruct") + 126 at RLMRealm.mm:104
    frame #18: 0x00000001045ec7bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #19: 0x00000001045f7390 libobjc.A.dylib`objc_destructInstance + 93
    frame #20: 0x00000001045f73c3 libobjc.A.dylib`object_dispose + 22
    frame #21: 0x000000010242a037 Realm`-[RLMRealm dealloc](self=0x00007f7fd0526970, _cmd="dealloc") + 247 at RLMRealm.mm:592
    frame #22: 0x0000000104601afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #23: 0x00000001028e782c RealmSwift`RealmSwift.Realm.deinit(self=0x00007f7fd2a36bf0) + 28 at Realm.swift:0
    frame #24: 0x00000001028e77f1 RealmSwift`RealmSwift.Realm.__deallocating_deinit + 17 at Realm.swift:0
    frame #25: 0x00000001017f7eda MyApp`@objc MyApp.MyAppRelationOperation.__ivar_destroyer + 42 at MyAppRelationOperation.swift:0
    frame #26: 0x00000001045ec7bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #27: 0x00000001045f7390 libobjc.A.dylib`objc_destructInstance + 93
    frame #28: 0x00000001045f73c3 libobjc.A.dylib`object_dispose + 22
    frame #29: 0x000000010419643f Foundation`-[NSOperation dealloc] + 89
    frame #30: 0x0000000104601afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #31: 0x0000000104a5b58d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #32: 0x0000000104601afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #33: 0x00000001041964c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #34: 0x0000000104601afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #35: 0x0000000104196420 Foundation`-[NSOperation dealloc] + 58
    frame #36: 0x0000000104601afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #37: 0x0000000105aa96b1 libsystem_blocks.dylib`_Block_release + 128
    frame #38: 0x0000000105a3249b libdispatch.dylib`_dispatch_client_callout + 8
    frame #39: 0x0000000105a1abef libdispatch.dylib`_dispatch_root_queue_drain + 1829
    frame #40: 0x0000000105a1a4c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #41: 0x0000000105d6a68f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #42: 0x0000000105d68365 libsystem_pthread.dylib`start_wqthread + 13
jpsim commented 8 years ago

@bdash would you mind taking a look at this? I'm unable to reproduce this myself.

bdash commented 8 years ago

I've written up a bug report against core since that appears to be where the incorrect state is.

@Legoless, would you be able to share the backtraces of all threads in your application when you hit this crash? It's possible there's a threading issue at play given the heavy concurrency you speak of, and the extra backtraces may provide more insight into that. You can get backtraces of all threads using bt all in the debugger console after your application has crashed.

Legoless commented 8 years ago

Thanks @bdash. This has definitely something to do with Lists or maybe even the RLMRealm notification listener.

This time the crash was in Thread 6, again while refresh call on Realm.

* thread #6: tid = 0x1d7d81, 0x000000010eafc0e7 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 295, queue = 'com.MyApp.database :: NSOperation 0x7fa63c79c190 (QOS: USER_INITIATED)', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
  * frame #0: 0x000000010eafc0e7 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 295
    frame #1: 0x000000010eb8b738 Realm`realm::Table::refresh_column_accessors(unsigned long) + 632
    frame #2: 0x000000010eba2b0a Realm`realm::Table::refresh_accessor_tree() + 666
    frame #3: 0x000000010eb166e8 Realm`realm::Group::advance_transact(unsigned long, unsigned long, realm::_impl::NoCopyInputStream&) + 600
    frame #4: 0x000000010ea1ae25 Realm`bool realm::SharedGroup::do_advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007fa63b95d200, observer=0x000070000021c3f8, version_id=(version = 18446744073709551615, index = 0), hist=0x00007fa63c5f5468)::TransactLogValidator*, realm::SharedGroup::VersionID, realm::_impl::History&) + 725 at group_shared.hpp:1060
    frame #5: 0x000000010ea1ab32 Realm`void realm::SharedGroup::advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007fa63b95d200, observer=0x000070000021c3f8, version_id=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 402 at group_shared.hpp:930
    frame #6: 0x000000010ea1a98b Realm`void realm::_impl::SharedGroupFriend::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007fa63b95d200, obs=0x000070000021c3f8, ver=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 59 at group_shared.hpp:1097
    frame #7: 0x000000010ea1a93b Realm`void realm::LangBindHelper::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007fa63b95d200, observer=0x000070000021c3f8, version=(version = 18446744073709551615, index = 0))::TransactLogValidator&&, realm::SharedGroup::VersionID) + 59 at lang_bind_helper.hpp:352
    frame #8: 0x000000010ea1a865 Realm`auto realm::_impl::transaction::advance(this=0x000070000021c3e8, args=0x000070000021c3f8)::$_0::operator()<(anonymous namespace)::TransactLogValidator&>((anonymous namespace)::TransactLogValidator&&&) const + 69 at transact_log_handler.cpp:438
    frame #9: 0x000000010ea1a48c Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x000070000021c3f8, context=0x00007fa63f81c080, sg=0x00007fa63b95d200, func=0x000070000021c3e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 1132 at transact_log_handler.cpp:222
    frame #10: 0x000000010ea19bfe Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x000070000021c3f8, context=0x00007fa63f81c080, sg=0x00007fa63b95d200, func=0x000070000021c3e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 62 at transact_log_handler.cpp:204
    frame #11: 0x000000010ea19baa Realm`realm::_impl::transaction::advance(sg=0x00007fa63b95d200, context=0x00007fa63f81c080, version=(version = 18446744073709551615, index = 0)) + 90 at transact_log_handler.cpp:437
    frame #12: 0x000000010ea1412a Realm`realm::Realm::refresh(this=0x00007fa63ada17c0) + 266 at shared_realm.cpp:409
    frame #13: 0x000000010e9e508e Realm`-[RLMRealm refresh](self=0x00007fa63f84c2f0, _cmd="refresh") + 46 at RLMRealm.mm:595
    frame #14: 0x000000010eea242d RealmSwift`RealmSwift.Realm.refresh (self=0x00007fa63af27280)() -> Swift.Bool + 45 at Realm.swift:526
    frame #15: 0x000000010ddb6757 MyApp`MyApp.MyAppUpdateOperation.realm.getter : RealmSwift.Realm(self=0x00007fa63c79c190) + 823 at MyAppUpdateOperation.swift:25
    frame #16: 0x000000010ddb7392 MyApp`MyApp.MyAppUpdateOperation.main <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (self=0x00007fa63c79c190)() -> () + 290 at MyAppUpdateOperation.swift:59
    frame #17: 0x000000010ddb80ad MyApp`@objc MyApp.MyAppUpdateOperation.main <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (MyApp.MyAppUpdateOperation<A>)() -> () + 61 at MyAppUpdateOperation.swift:0
    frame #18: 0x000000011073bf8a Foundation`-[__NSOperationInternal _start:] + 646
    frame #19: 0x000000011073bb9b Foundation`__NSOQSchedule_f + 194
    frame #20: 0x0000000111fed49b libdispatch.dylib`_dispatch_client_callout + 8
    frame #21: 0x0000000111fd38ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #22: 0x0000000111fd2e0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #23: 0x0000000111fd5a56 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #24: 0x0000000111fd54c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #25: 0x000000011232568f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #26: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

The entire stack trace is below. The interesting thing to look at might be Thread 14, since the way I see it it is in process of deleting something with BpTree. Maybe we need an additional race condition lock somewhere there?

warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
  thread #1: tid = 0x1d7b91, 0x000000011235b386 libsystem_kernel.dylib`mach_msg_trap + 10, queue = 'com.apple.main-thread'
    frame #0: 0x000000011235b386 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000011235a7c7 libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x0000000111054b64 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000111053fbf CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x0000000111053828 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x000000011434dad2 GraphicsServices`GSEventRunModal + 161
    frame #6: 0x000000010f1ba610 UIKit`UIApplicationMain + 171
    frame #7: 0x000000010ddcb37d MyApp`main + 109 at AppDelegate.swift:16
    frame #8: 0x000000011202192d libdyld.dylib`start + 1
    frame #9: 0x000000011202192d libdyld.dylib`start + 1

  thread #2: tid = 0x1d7d4a, 0x0000000112361fde libsystem_kernel.dylib`kevent64 + 10, queue = 'com.apple.libdispatch-manager'
    frame #0: 0x0000000112361fde libsystem_kernel.dylib`kevent64 + 10
    frame #1: 0x0000000111fdc4c8 libdispatch.dylib`_dispatch_mgr_invoke + 260
    frame #2: 0x0000000111fdc262 libdispatch.dylib`_dispatch_mgr_thread + 54

  thread #3: tid = 0x1d7d4b, 0x000000010e497e08 Firebase`leveldb::InternalKeyComparator::Compare(leveldb::Slice const&, leveldb::Slice const&) const + 24, queue = 'FirebaseWorker'
    frame #0: 0x000000010e497e08 Firebase`leveldb::InternalKeyComparator::Compare(leveldb::Slice const&, leveldb::Slice const&) const + 24
    frame #1: 0x000000010e499b92 Firebase`leveldb::MemTable::KeyComparator::operator()(char const*, char const*) const + 130
    frame #2: 0x000000010e499f8f Firebase`leveldb::SkipList<char const*, leveldb::MemTable::KeyComparator>::Insert(char const* const&) + 95
    frame #3: 0x000000010e499cfc Firebase`leveldb::MemTable::Add(unsigned long long, leveldb::ValueType, leveldb::Slice const&, leveldb::Slice const&) + 236
    frame #4: 0x000000010e4a5664 Firebase`leveldb::(anonymous namespace)::MemTableInserter::Put(leveldb::Slice const&, leveldb::Slice const&) + 36
    frame #5: 0x000000010e4a527b Firebase`leveldb::WriteBatch::Iterate(leveldb::WriteBatch::Handler*) const + 379
    frame #6: 0x000000010e4a556d Firebase`leveldb::WriteBatchInternal::InsertInto(leveldb::WriteBatch const*, leveldb::MemTable*) + 61
    frame #7: 0x000000010e4936c6 Firebase`leveldb::DBImpl::Write(leveldb::WriteOptions const&, leveldb::WriteBatch*) + 758
    frame #8: 0x000000010e4931e2 Firebase`leveldb::DBImpl::Put(leveldb::WriteOptions const&, leveldb::Slice const&, leveldb::Slice const&) + 82
    frame #9: 0x000000010e425d68 Firebase`-[APLevelDB setData:forKey:](self=<unavailable>, _cmd=<unavailable>, data=<unavailable>, key=<unavailable>) + 200 at APLevelDB.mm:151 [opt]
    frame #10: 0x000000010e417d39 Firebase`-[FLevelDBStorageEngine saveTrackedQuery:](self=<unavailable>, _cmd="saveTrackedQuery:", query=<unavailable>) + 1117 at FLevelDBStorageEngine.m:480 [opt]
    frame #11: 0x000000010e41b9b0 Firebase`-[FTrackedQueryManager setQueryActive:forQuery:](self=0x00007fa63c1a2f40, _cmd="setQueryActive:forQuery:", isActive=<unavailable>, query=<unavailable>) + 278 at FTrackedQueryManager.m:85 [opt]
    frame #12: 0x000000010e41a664 Firebase`-[FPersistenceManager setQueryActive:](self=<unavailable>, _cmd=<unavailable>, spec=<unavailable>) + 79 at FPersistenceManager.m:129 [opt]
    frame #13: 0x000000010e474ddf Firebase`-[FSyncTree addEventRegistration:forQuery:](self=0x00007fa63c1cd970, _cmd="addEventRegistration:forQuery:", eventRegistration=<unavailable>, query=<unavailable>) + 332 at FSyncTree.m:360 [opt]
    frame #14: 0x000000010e461c76 Firebase`-[FRepo addEventRegistration:forQuery:](self=0x00007fa63c213ed0, _cmd=<unavailable>, eventRegistration=<unavailable>, query=<unavailable>) + 220 at FRepo.m:371 [opt]
    frame #15: 0x000000010e4378bc Firebase`__63-[FQuery observeValueEventWithHandle:withBlock:cancelCallback:]_block_invoke(.block_descriptor=<unavailable>) + 94 at FQuery.m:501 [opt]
    frame #16: 0x0000000111fcce5d libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #17: 0x0000000111fed49b libdispatch.dylib`_dispatch_client_callout + 8
    frame #18: 0x0000000111fd38ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #19: 0x0000000111fd2e0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #20: 0x0000000111fed49b libdispatch.dylib`_dispatch_client_callout + 8
    frame #21: 0x0000000111fd5bef libdispatch.dylib`_dispatch_root_queue_drain + 1829
    frame #22: 0x0000000111fd54c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #23: 0x000000011232568f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #24: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #4: tid = 0x1d7d4c, 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x0000000112325729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #5: tid = 0x1d7d7f, 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x0000000112325729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

* thread #6: tid = 0x1d7d81, 0x000000010eafc0e7 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 295, queue = 'com.MyApp.database :: NSOperation 0x7fa63c79c190 (QOS: USER_INITIATED)'
    frame #0: 0x000000010eafc0e7 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 295
    frame #1: 0x000000010eb8b738 Realm`realm::Table::refresh_column_accessors(unsigned long) + 632
    frame #2: 0x000000010eba2b0a Realm`realm::Table::refresh_accessor_tree() + 666
    frame #3: 0x000000010eb166e8 Realm`realm::Group::advance_transact(unsigned long, unsigned long, realm::_impl::NoCopyInputStream&) + 600
  * frame #4: 0x000000010ea1ae25 Realm`bool realm::SharedGroup::do_advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007fa63b95d200, observer=0x000070000021c3f8, version_id=(version = 18446744073709551615, index = 0), hist=0x00007fa63c5f5468)::TransactLogValidator*, realm::SharedGroup::VersionID, realm::_impl::History&) + 725 at group_shared.hpp:1060
    frame #5: 0x000000010ea1ab32 Realm`void realm::SharedGroup::advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007fa63b95d200, observer=0x000070000021c3f8, version_id=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 402 at group_shared.hpp:930
    frame #6: 0x000000010ea1a98b Realm`void realm::_impl::SharedGroupFriend::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007fa63b95d200, obs=0x000070000021c3f8, ver=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 59 at group_shared.hpp:1097
    frame #7: 0x000000010ea1a93b Realm`void realm::LangBindHelper::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007fa63b95d200, observer=0x000070000021c3f8, version=(version = 18446744073709551615, index = 0))::TransactLogValidator&&, realm::SharedGroup::VersionID) + 59 at lang_bind_helper.hpp:352
    frame #8: 0x000000010ea1a865 Realm`auto realm::_impl::transaction::advance(this=0x000070000021c3e8, args=0x000070000021c3f8)::$_0::operator()<(anonymous namespace)::TransactLogValidator&>((anonymous namespace)::TransactLogValidator&&&) const + 69 at transact_log_handler.cpp:438
    frame #9: 0x000000010ea1a48c Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x000070000021c3f8, context=0x00007fa63f81c080, sg=0x00007fa63b95d200, func=0x000070000021c3e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 1132 at transact_log_handler.cpp:222
    frame #10: 0x000000010ea19bfe Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x000070000021c3f8, context=0x00007fa63f81c080, sg=0x00007fa63b95d200, func=0x000070000021c3e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 62 at transact_log_handler.cpp:204
    frame #11: 0x000000010ea19baa Realm`realm::_impl::transaction::advance(sg=0x00007fa63b95d200, context=0x00007fa63f81c080, version=(version = 18446744073709551615, index = 0)) + 90 at transact_log_handler.cpp:437
    frame #12: 0x000000010ea1412a Realm`realm::Realm::refresh(this=0x00007fa63ada17c0) + 266 at shared_realm.cpp:409
    frame #13: 0x000000010e9e508e Realm`-[RLMRealm refresh](self=0x00007fa63f84c2f0, _cmd="refresh") + 46 at RLMRealm.mm:595
    frame #14: 0x000000010eea242d RealmSwift`RealmSwift.Realm.refresh (self=0x00007fa63af27280)() -> Swift.Bool + 45 at Realm.swift:526
    frame #15: 0x000000010ddb6757 MyApp`MyApp.MyAppUpdateOperation.realm.getter : RealmSwift.Realm(self=0x00007fa63c79c190) + 823 at MyAppUpdateOperation.swift:25
    frame #16: 0x000000010ddb7392 MyApp`MyApp.MyAppUpdateOperation.main <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (self=0x00007fa63c79c190)() -> () + 290 at MyAppUpdateOperation.swift:59
    frame #17: 0x000000010ddb80ad MyApp`@objc MyApp.MyAppUpdateOperation.main <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (MyApp.MyAppUpdateOperation<A>)() -> () + 61 at MyAppUpdateOperation.swift:0
    frame #18: 0x000000011073bf8a Foundation`-[__NSOperationInternal _start:] + 646
    frame #19: 0x000000011073bb9b Foundation`__NSOQSchedule_f + 194
    frame #20: 0x0000000111fed49b libdispatch.dylib`_dispatch_client_callout + 8
    frame #21: 0x0000000111fd38ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #22: 0x0000000111fd2e0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #23: 0x0000000111fd5a56 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #24: 0x0000000111fd54c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #25: 0x000000011232568f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #26: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #7: tid = 0x1d7d86, 0x000000011233dfcd libsystem_platform.dylib`_platform_memmove$VARIANT$Haswell + 173, queue = 'com.apple.root.user-initiated-qos'
    frame #0: 0x000000011233dfcd libsystem_platform.dylib`_platform_memmove$VARIANT$Haswell + 173
    frame #1: 0x0000000111a9862a libswiftCore.dylib`Swift._StringCore._copyInPlace (inout Swift._StringCore)(newSize : Swift.Int, newCapacity : Swift.Int, minElementWidth : Swift.Int) -> () + 170
    frame #2: 0x0000000111ad0648 libswiftCore.dylib`function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of Swift._StringCore.append (inout Swift._StringCore)(Swift._StringCore) -> () + 264
    frame #3: 0x0000000111ad4071 libswiftCore.dylib`function signature specialization <Arg[1] = Dead> of Swift.String.init (Swift.String.Type)(stringInterpolation : Swift.Array<Swift.String>...) -> Swift.String + 161
    frame #4: 0x000000010de15e99 MyApp`MyApp.MyAppFirebaseSubscription.description.getter : Swift.String(self=0x00007fa63c6a3c50) + 1033 at MyAppFirebaseSubscription.swift:48
    frame #5: 0x000000010de15a52 MyApp`@objc MyApp.MyAppFirebaseSubscription.description.getter : Swift.String + 34 at MyAppFirebaseSubscription.swift:0
    frame #6: 0x0000000111e601fb libswiftFoundation.dylib`protocol witness for Swift.CustomStringConvertible.description.getter : Swift.String in conformance __ObjC.NSObject : Swift.CustomStringConvertible in Foundation + 43
    frame #7: 0x0000000111a4aa4f libswiftCore.dylib`Swift._print_unlocked <A, B where B: Swift.OutputStreamType> (A, inout B) -> () + 559
    frame #8: 0x0000000111a2a470 libswiftCore.dylib`Swift.String.init <A> (Swift.String.Type)(stringInterpolationSegment : A) -> Swift.String + 64
    frame #9: 0x000000010de2019c MyApp`MyApp.MyAppFirebaseSubscription.(self=0x00007fa63c6a3c50) -> (A.Type) -> ()).(implicit closure #1) + 156 at MyAppFirebaseSubscription.swift:116
    frame #10: 0x000000010de1db0d MyApp`partial apply forwarder for MyApp.MyAppFirebaseSubscription.(subscribe <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (MyApp.MyAppFirebaseSubscription) -> (A.Type) -> ()).(implicit closure #1) + 93 at MyAppFirebaseSubscription.swift:0
    frame #11: 0x00000001106e6512 XCGLogger`XCGLogger.XCGLogger.logln (logLevel=Debug, functionName="subscribe", fileName="/Users/legoless/Dropbox/Work/Povio/MyApp/MyApp-iOS/MyApp/MyApp/Model/Local/MyAppFirebaseSubscription.swift", lineNumber=116, closure=(MyApp`partial apply forwarder for MyApp.MyAppFirebaseSubscription.(subscribe <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (MyApp.MyAppFirebaseSubscription) -> (A.Type) -> ()).(implicit closure #1) at MyAppFirebaseSubscription.swift), self=0x00007fa63ac4dc50)(XCGLogger.XCGLogger.LogLevel, functionName : Swift.String, fileName : Swift.String, lineNumber : Swift.Int, closure : () -> Swift.Optional<Swift.String>) -> () + 1650 at XCGLogger.swift:609
    frame #12: 0x00000001106e931a XCGLogger`XCGLogger.XCGLogger.debug (closure=<unavailable>, functionName="subscribe", fileName="/Users/legoless/Dropbox/Work/Povio/MyApp/MyApp-iOS/MyApp/MyApp/Model/Local/MyAppFirebaseSubscription.swift", lineNumber=116, self=0x00007fa63ac4dc50)(@autoclosure () -> Swift.Optional<Swift.String>, functionName : Swift.String, fileName : Swift.String, lineNumber : Swift.Int) -> () + 282 at XCGLogger.swift:692
    frame #13: 0x000000010de17637 MyApp`MyApp.MyAppFirebaseSubscription.subscribe <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (type=0x000000010df52ca0, self=0x00007fa63c6a3c50)(A.Type) -> () + 359 at MyAppFirebaseSubscription.swift:116
    frame #14: 0x000000010de7b896 MyApp`static MyApp.Chapter.updateSubscriptionModel (subscription=0x00007fa63f920300, data=9 key/value pairs, metadata=1 key/value pair, self=0x000000010df53d30)(MyApp.MyAppFirebaseSubscription, data : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, metadata : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>) -> Swift.Bool + 5174 at Chapter+Mappable.swift:85
    frame #15: 0x000000010de7bbd2 MyApp`@objc static MyApp.Chapter.updateSubscriptionModel (MyApp.Chapter.Type)(MyApp.MyAppFirebaseSubscription, data : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, metadata : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>) -> Swift.Bool + 306 at Chapter+Mappable.swift:0
    frame #16: 0x000000010de7c1f3 MyApp`dynamic static MyApp.Chapter.updateSubscriptionModel (MyApp.Chapter.Type)(MyApp.MyAppFirebaseSubscription, data : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, metadata : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>) -> Swift.Bool + 195 at Chapter+Mappable.swift:42
    frame #17: 0x000000010de7bc2b MyApp`protocol witness for static MyApp.MyAppMappable.updateSubscriptionModel <A where A: MyApp.MyAppMappable> (A.Type)(MyApp.MyAppFirebaseSubscription, data : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, metadata : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>) -> Swift.Bool in conformance MyApp.Chapter : MyApp.MyAppMappable in MyApp + 27 at Chapter+Mappable.swift:42
    frame #18: 0x000000010de2547c MyApp`MyApp.MyAppFirebaseSubscription.(self=0x00007fa63f920300, data=9 key/value pairs, metadata=1 key/value pair, shouldNotify=false) <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (MyApp.MyAppFirebaseSubscription) -> (Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, type : A.Type, metadata : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, shouldNotify : Swift.Bool) -> __ObjC.NSOperation).(closure #1) + 380 at MyAppFirebaseSubscription.swift:424
    frame #19: 0x000000010de1e688 MyApp`partial apply forwarder for MyApp.MyAppFirebaseSubscription.((completionOperationFromData in _4D2C865DCDF44D883CAC3920AB07BB2F) <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> (MyApp.MyAppFirebaseSubscription) -> (Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, type : A.Type, metadata : Swift.Optional<Swift.Dictionary<Swift.String, Swift.AnyObject>>, shouldNotify : Swift.Bool) -> __ObjC.NSOperation).(closure #1) + 328 at MyAppFirebaseSubscription.swift:0
    frame #20: 0x000000010de22ba5 MyApp`reabstraction thunk helper <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) + 21 at MyAppFirebaseSubscription.swift:0
    frame #21: 0x000000010de1e73d MyApp`partial apply forwarder for reabstraction thunk helper <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) with unmangled suffix "24" + 109 at MyAppFirebaseSubscription.swift:0
    frame #22: 0x000000010de22bd8 MyApp`reabstraction thunk helper <A where A: RealmSwift.Object, A: MyApp.MyAppMappable> from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> (@unowned ()) + 40 at MyAppFirebaseSubscription.swift:0
    frame #23: 0x000000010dd6ea67 MyApp`reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_unowned @convention(block) () -> (@unowned ()) + 39 at UIViewController+Alert.swift:0
    frame #24: 0x000000011081c957 Foundation`__103+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke124 + 16
    frame #25: 0x0000000111fcce5d libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #26: 0x0000000111fed49b libdispatch.dylib`_dispatch_client_callout + 8
    frame #27: 0x0000000111fd5bef libdispatch.dylib`_dispatch_root_queue_drain + 1829
    frame #28: 0x0000000111fd54c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #29: 0x000000011232568f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #30: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #8: tid = 0x1d7d87, 0x000000011235b386 libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.apple.NSURLConnectionLoader'
    frame #0: 0x000000011235b386 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000011235a7c7 libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x0000000111054b64 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000111053fbf CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x0000000111053828 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x00000001129d43c4 CFNetwork`+[NSURLConnection(Loader) _resourceLoadLoop:] + 412
    frame #6: 0x0000000110832dfb Foundation`__NSThread__start__ + 1198
    frame #7: 0x0000000112325c13 libsystem_pthread.dylib`_pthread_body + 131
    frame #8: 0x0000000112325b90 libsystem_pthread.dylib`_pthread_start + 168
    frame #9: 0x0000000112323375 libsystem_pthread.dylib`thread_start + 13

  thread #9: tid = 0x1d7d89, 0x000000011235b386 libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.squareup.SocketRocket.NetworkThread'
    frame #0: 0x000000011235b386 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000011235a7c7 libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x0000000111054b64 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000111053fbf CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x0000000111053828 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x00000001107952f1 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 267
    frame #6: 0x000000010e484759 Firebase`-[_FSRRunLoopThread main](self=0x00007fa63ada3d10, _cmd=<unavailable>) + 238 at FSRWebSocket.m:1791 [opt]
    frame #7: 0x0000000110832dfb Foundation`__NSThread__start__ + 1198
    frame #8: 0x0000000112325c13 libsystem_pthread.dylib`_pthread_body + 131
    frame #9: 0x0000000112325b90 libsystem_pthread.dylib`_pthread_start + 168
    frame #10: 0x0000000112323375 libsystem_pthread.dylib`thread_start + 13

  thread #10: tid = 0x1d7d8a, 0x0000000112361fc6 libsystem_kernel.dylib`kevent + 10, name = 'RLMRealm notification listener'
    frame #0: 0x0000000112361fc6 libsystem_kernel.dylib`kevent + 10
    frame #1: 0x000000010e852483 Realm`realm::_impl::ExternalCommitHelper::listen(this=0x00007fa63ace2cc0) + 467 at external_commit_helper.cpp:199
    frame #2: 0x000000010e853397 Realm`realm::_impl::ExternalCommitHelper::ExternalCommitHelper(this=0x00007fa63c24ff30)::$_0::operator()() const + 23 at external_commit_helper.cpp:159
    frame #3: 0x000000010e85336d Realm`_ZNSt3__112__async_funcIZN5realm5_impl20ExternalCommitHelperC1ERNS2_16RealmCoordinatorEE3$_0JEE9__executeIJEEEvNS_15__tuple_indicesIJXspT_EEEE [inlined] std::__1::__invoke<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>(__f=0x00007fa63c24ff30)::$_0>(fp)(std::__1::forward<>(fp0))), realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0&&) + 61 at __functional_base:415
    frame #4: 0x000000010e85335c Realm`_ZNSt3__112__async_funcIZN5realm5_impl20ExternalCommitHelperC1ERNS2_16RealmCoordinatorEE3$_0JEE9__executeIJEEEvNS_15__tuple_indicesIJXspT_EEEE(this=0x00007fa63c24ff30, (null)=__tuple_indices<> @ 0x0000700000428c10) + 44 at future:2342
    frame #5: 0x000000010e853325 Realm`std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>::operator(this=0x00007fa63c24ff30)() + 21 at future:2335
    frame #6: 0x000000010e85324f Realm`std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::__execute(this=0x00007fa63c24fea0) + 31 at future:1029
    frame #7: 0x000000010e853cfd Realm`std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) [inlined] std::__1::__invoke<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*, void>(__f=0x00007fa63c24ff40, __a0=0x00007fa63c24ff50)::$_0> >*>(fp0)).*fp(std::__1::forward<>(fp1))), void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*&&)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*&&) + 136 at __functional_base:382
    frame #8: 0x000000010e853c75 Realm`std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) [inlined] _ZNSt3__116__thread_executeIMNS_19__async_assoc_stateIvNS_12__async_funcIZN5realm5_impl20ExternalCommitHelperC1ERNS4_16RealmCoordinatorEE3$_0JEEEEEFvvEJPSA_EJLm1EEEEvRNS_5tupleIJT_DpT0_EEENS_15__tuple_indicesIJXspT1_EEEE(__t=0x00007fa63c24ff40, (null)=__tuple_indices<1> @ 0x0000700000428ea0) + 40 at thread:337
    frame #9: 0x000000010e853c4d Realm`std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(__vp=0x00007fa63c24ff40) + 365 at thread:347
    frame #10: 0x0000000112325c13 libsystem_pthread.dylib`_pthread_body + 131
    frame #11: 0x0000000112325b90 libsystem_pthread.dylib`_pthread_start + 168
    frame #12: 0x0000000112323375 libsystem_pthread.dylib`thread_start + 13

  thread #11: tid = 0x1d7d8b, 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x0000000112325729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #12: tid = 0x1d7d8c, 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x0000000112325729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #13: tid = 0x1d7d90, 0x0000000112361176 libsystem_kernel.dylib`__select + 10, name = 'com.apple.CFSocket.private'
    frame #0: 0x0000000112361176 libsystem_kernel.dylib`__select + 10
    frame #1: 0x000000011109a1fa CoreFoundation`__CFSocketManager + 746
    frame #2: 0x0000000112325c13 libsystem_pthread.dylib`_pthread_body + 131
    frame #3: 0x0000000112325b90 libsystem_pthread.dylib`_pthread_start + 168
    frame #4: 0x0000000112323375 libsystem_pthread.dylib`thread_start + 13

  thread #14: tid = 0x1d7d91, 0x000000010e83b910 Realm`realm::ArrayInteger::~ArrayInteger(this=0x00007fa63c7edfa0) at array_integer.hpp:36, queue = 'com.MyApp.database :: NSOperation 0x7fa63f85f600 (QOS: USER_INITIATED)'
    frame #0: 0x000000010e83b910 Realm`realm::ArrayInteger::~ArrayInteger(this=0x00007fa63c7edfa0) at array_integer.hpp:36
    frame #1: 0x000000010e847515 Realm`realm::BpTreeBase::~BpTreeBase() [inlined] std::__1::default_delete<realm::Array>::operator(this=0x00007fa63c7edfa0, __ptr=0x00007fa63c7ef520)(realm::Array*) const + 181 at memory:2459
    frame #2: 0x000000010e8474f3 Realm`realm::BpTreeBase::~BpTreeBase() [inlined] std::__1::unique_ptr<realm::Array, std::__1::default_delete<realm::Array> >::reset(this=0x00007fa63c7edfa0, __p=0x0000000000000000) + 96 at memory:2658
    frame #3: 0x000000010e847493 Realm`realm::BpTreeBase::~BpTreeBase() [inlined] std::__1::unique_ptr<realm::Array, std::__1::default_delete<realm::Array> >::~unique_ptr(this=0x00007fa63c7edfa0) + 16 at memory:2626
    frame #4: 0x000000010e847483 Realm`realm::BpTreeBase::~BpTreeBase() [inlined] std::__1::unique_ptr<realm::Array, std::__1::default_delete<realm::Array> >::~unique_ptr(this=0x00007fa63c7edfa0) + 8 at memory:2626
    frame #5: 0x000000010e84747b Realm`realm::BpTreeBase::~BpTreeBase(this=0x00007fa63c7edfa0) + 27 at bptree.hpp:39
    frame #6: 0x000000010e847455 Realm`realm::BpTree<long long>::~BpTree(this=0x00007fa63c7edfa0) + 21 at bptree.hpp:87
    frame #7: 0x000000010e847435 Realm`realm::BpTree<long long>::~BpTree(this=0x00007fa63c7edfa0) + 21 at bptree.hpp:87
    frame #8: 0x000000010e832e73 Realm`realm::Column<long long>::~Column(this=0x00007fa63c7edf88) + 67 at column.hpp:973
    frame #9: 0x000000010e839b35 Realm`realm::Column<long long>::~Column(this=0x00007fa63c7edf88) + 21 at column.hpp:972
    frame #10: 0x000000010e83315c Realm`realm::RowIndexes::~RowIndexes(this=0x00007fa63c7edf80) + 44 at views.hpp:40
    frame #11: 0x000000010e8330e4 Realm`realm::LinkView::~LinkView(this=0x00007fa63c7edf80) + 164 at link_view.hpp:182
    frame #12: 0x000000010e833185 Realm`realm::LinkView::~LinkView(this=0x00007fa63c7edf80) + 21 at link_view.hpp:177
    frame #13: 0x000000010e8331a9 Realm`realm::LinkView::~LinkView(this=0x00007fa63c7edf80) + 25 at link_view.hpp:177
    frame #14: 0x000000010e83a4c0 Realm`realm::LinkView::unbind_ptr(this=0x00007fa63c7edf80) const + 80 at link_view.hpp:194
    frame #15: 0x000000010e8b0dbd Realm`realm::util::bind_ptr<realm::LinkView>::unbind(this=0x00007fa63c7ef188) + 45 at bind_ptr.hpp:150
    frame #16: 0x000000010e8b0d85 Realm`realm::util::bind_ptr<realm::LinkView>::~bind_ptr(this=0x00007fa63c7ef188) + 21 at bind_ptr.hpp:58
    frame #17: 0x000000010e8b0d65 Realm`realm::util::bind_ptr<realm::LinkView>::~bind_ptr(this=0x00007fa63c7ef188) + 21 at bind_ptr.hpp:58
    frame #18: 0x000000010e8bf393 Realm`-[RLMArrayLinkView .cxx_destruct](self=0x00007fa63c7ef160, _cmd=".cxx_destruct") + 275 at RLMArrayLinkView.mm:39
    frame #19: 0x0000000110ba77bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #20: 0x0000000110bb2390 libobjc.A.dylib`objc_destructInstance + 93
    frame #21: 0x0000000110bb23c3 libobjc.A.dylib`object_dispose + 22
    frame #22: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #23: 0x000000010e8c0857 Realm`-[RLMListBase .cxx_destruct](self=0x00007fa63c7eb130, _cmd=".cxx_destruct") + 55 at RLMListBase.mm:28
    frame #24: 0x0000000110ba77bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #25: 0x0000000110bb2390 libobjc.A.dylib`objc_destructInstance + 93
    frame #26: 0x0000000110bb23c3 libobjc.A.dylib`object_dispose + 22
    frame #27: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #28: 0x000000010de63658 MyApp`@objc MyApp.Chapter.__ivar_destroyer + 248 at Chapter.swift:0
    frame #29: 0x0000000110ba77bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #30: 0x0000000110bb2390 libobjc.A.dylib`objc_destructInstance + 93
    frame #31: 0x0000000110bb23c3 libobjc.A.dylib`object_dispose + 22
    frame #32: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #33: 0x000000010ddb820f MyApp`@objc MyApp.MyAppUpdateOperation.__ivar_destroyer + 239 at MyAppUpdateOperation.swift:0
    frame #34: 0x0000000110ba77bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #35: 0x0000000110bb2390 libobjc.A.dylib`objc_destructInstance + 93
    frame #36: 0x0000000110bb23c3 libobjc.A.dylib`object_dispose + 22
    frame #37: 0x000000011075143f Foundation`-[NSOperation dealloc] + 89
    frame #38: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #39: 0x000000011101658d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #40: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #41: 0x00000001107514c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #42: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #43: 0x0000000110751420 Foundation`-[NSOperation dealloc] + 58
    frame #44: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #45: 0x000000011101658d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #46: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #47: 0x00000001107514c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #48: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #49: 0x0000000110751420 Foundation`-[NSOperation dealloc] + 58
    frame #50: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #51: 0x000000011101658d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #52: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #53: 0x00000001107514c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #54: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #55: 0x0000000110751420 Foundation`-[NSOperation dealloc] + 58
    frame #56: 0x0000000110bbcafe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #57: 0x000000011073bc80 Foundation`__NSOQSchedule_f + 423
    frame #58: 0x0000000111fed49b libdispatch.dylib`_dispatch_client_callout + 8
    frame #59: 0x0000000111fd38ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #60: 0x0000000111fd2e0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #61: 0x0000000111fd5a56 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #62: 0x0000000111fd54c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #63: 0x000000011232568f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #64: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13

  thread #15: tid = 0x1d7d92, 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x00000001123616de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x0000000112325729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x0000000112323365 libsystem_pthread.dylib`start_wqthread + 13
bdash commented 8 years ago

Yes, thread 6 crashing while thread 14 is destroying a LinkView seems relevant. Usage of SharedGroup and its related accessors (e..g, LinkView) are tied to a single thread. It's possible that this is happening due to an RLMRealm, RLMArray or similar being unintentionally shared between threads. We have asserts in place to attempt to catch accidental sharing of objects across threads, but this case may be slipping through somehow.

bdash commented 8 years ago

@tg, do you have any thoughts on how to determine what's going on here? Would the thread sanitizer work for this sort of case?

tg commented 8 years ago

We can run a debugger...

Um, no, @bdash, probably not me who you wanted to mention ;-)

bdash commented 8 years ago

Sorry, @tg, tab completion failure! @tgoyne?

tgoyne commented 8 years ago

ThreadSanitizer currently doesn't support libdispatch, so it's not usable for actual iOS apps.

Extremely unfortunate timing between a realm being destroyed on the wrong thread and a reference begin acquired on the "proper" thread does seem like it could explain this crash.

Legoless commented 8 years ago

Another crash, this time it does not seem to be connected to a cross-threading operation directly.

warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
  thread #1: tid = 0x3094c2, 0x000000010b225386 libsystem_kernel.dylib`mach_msg_trap + 10, queue = 'com.apple.main-thread'
    frame #0: 0x000000010b225386 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000010b2247c7 libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x0000000109f1eb64 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000109f1dfbf CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x0000000109f1d828 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x000000010d217ad2 GraphicsServices`GSEventRunModal + 161
    frame #6: 0x0000000108084610 UIKit`UIApplicationMain + 171
    frame #7: 0x0000000106c8a0cd MyApp`main + 109 at AppDelegate.swift:16
    frame #8: 0x000000010aeeb92d libdyld.dylib`start + 1
    frame #9: 0x000000010aeeb92d libdyld.dylib`start + 1

  thread #2: tid = 0x3094ff, 0x000000010b22bfde libsystem_kernel.dylib`kevent64 + 10, queue = 'com.apple.libdispatch-manager'
    frame #0: 0x000000010b22bfde libsystem_kernel.dylib`kevent64 + 10
    frame #1: 0x000000010aea64c8 libdispatch.dylib`_dispatch_mgr_invoke + 260
    frame #2: 0x000000010aea6262 libdispatch.dylib`_dispatch_mgr_thread + 54

  thread #3: tid = 0x309501, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #4: tid = 0x309502, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #5: tid = 0x309503, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #6: tid = 0x309506, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #7: tid = 0x309509, 0x000000010aa522af libswiftCore.dylib`_swift_release_(swift::HeapObject*) + 15, queue = 'com.apple.root.user-initiated-qos'
    frame #0: 0x000000010aa522af libswiftCore.dylib`_swift_release_(swift::HeapObject*) + 15
    frame #1: 0x0000000106c76eb3 MyApp`@objc MyApp.MyAppUpdateOperation.__ivar_destroyer + 67 at MyAppUpdateOperation.swift:0
    frame #2: 0x0000000109a717bb libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 127
    frame #3: 0x0000000109a7c390 libobjc.A.dylib`objc_destructInstance + 93
    frame #4: 0x0000000109a7c3c3 libobjc.A.dylib`object_dispose + 22
    frame #5: 0x000000010961b43f Foundation`-[NSOperation dealloc] + 89
    frame #6: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #7: 0x0000000109ee058d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #8: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #9: 0x000000010961b4c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #10: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #11: 0x000000010961b420 Foundation`-[NSOperation dealloc] + 58
    frame #12: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #13: 0x0000000109ee058d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #14: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #15: 0x000000010961b4c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #16: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #17: 0x000000010961b420 Foundation`-[NSOperation dealloc] + 58
    frame #18: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #19: 0x0000000109ee058d CoreFoundation`-[__NSArrayM dealloc] + 157
    frame #20: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #21: 0x000000010961b4c6 Foundation`-[__NSOperationInternal dealloc] + 118
    frame #22: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #23: 0x000000010961b420 Foundation`-[NSOperation dealloc] + 58
    frame #24: 0x0000000109a86afe libobjc.A.dylib`objc_object::sidetable_release(bool) + 232
    frame #25: 0x000000010af2e6b1 libsystem_blocks.dylib`_Block_release + 128
    frame #26: 0x000000010aeb749b libdispatch.dylib`_dispatch_client_callout + 8
    frame #27: 0x000000010ae9fbef libdispatch.dylib`_dispatch_root_queue_drain + 1829
    frame #28: 0x000000010ae9f4c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #29: 0x000000010b1ef68f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #30: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #8: tid = 0x30950a, 0x000000010b225386 libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.apple.NSURLConnectionLoader'
    frame #0: 0x000000010b225386 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000010b2247c7 libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x0000000109f1eb64 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000109f1dfbf CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x0000000109f1d828 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x000000010b89e3c4 CFNetwork`+[NSURLConnection(Loader) _resourceLoadLoop:] + 412
    frame #6: 0x00000001096fcdfb Foundation`__NSThread__start__ + 1198
    frame #7: 0x000000010b1efc13 libsystem_pthread.dylib`_pthread_body + 131
    frame #8: 0x000000010b1efb90 libsystem_pthread.dylib`_pthread_start + 168
    frame #9: 0x000000010b1ed375 libsystem_pthread.dylib`thread_start + 13

  thread #9: tid = 0x30950b, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #10: tid = 0x30950c, 0x000000010b22bfc6 libsystem_kernel.dylib`kevent + 10, name = 'RLMRealm notification listener'
    frame #0: 0x000000010b22bfc6 libsystem_kernel.dylib`kevent + 10
    frame #1: 0x000000010771c483 Realm`realm::_impl::ExternalCommitHelper::listen(this=0x00007fb05a363d30) + 467 at external_commit_helper.cpp:199
    frame #2: 0x000000010771d397 Realm`realm::_impl::ExternalCommitHelper::ExternalCommitHelper(this=0x00007fb05a363eb0)::$_0::operator()() const + 23 at external_commit_helper.cpp:159
    frame #3: 0x000000010771d36d Realm`_ZNSt3__112__async_funcIZN5realm5_impl20ExternalCommitHelperC1ERNS2_16RealmCoordinatorEE3$_0JEE9__executeIJEEEvNS_15__tuple_indicesIJXspT_EEEE [inlined] std::__1::__invoke<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>(__f=0x00007fb05a363eb0)::$_0>(fp)(std::__1::forward<>(fp0))), realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0&&) + 61 at __functional_base:415
    frame #4: 0x000000010771d35c Realm`_ZNSt3__112__async_funcIZN5realm5_impl20ExternalCommitHelperC1ERNS2_16RealmCoordinatorEE3$_0JEE9__executeIJEEEvNS_15__tuple_indicesIJXspT_EEEE(this=0x00007fb05a363eb0, (null)=__tuple_indices<> @ 0x0000700000428c10) + 44 at future:2342
    frame #5: 0x000000010771d325 Realm`std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>::operator(this=0x00007fb05a363eb0)() + 21 at future:2335
    frame #6: 0x000000010771d24f Realm`std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::__execute(this=0x00007fb05a363e20) + 31 at future:1029
    frame #7: 0x000000010771dcfd Realm`std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) [inlined] std::__1::__invoke<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*, void>(__f=0x00007fb05a360120, __a0=0x00007fb05a360130)::$_0> >*>(fp0)).*fp(std::__1::forward<>(fp1))), void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*&&)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*&&) + 136 at __functional_base:382
    frame #8: 0x000000010771dc75 Realm`std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) [inlined] _ZNSt3__116__thread_executeIMNS_19__async_assoc_stateIvNS_12__async_funcIZN5realm5_impl20ExternalCommitHelperC1ERNS4_16RealmCoordinatorEE3$_0JEEEEEFvvEJPSA_EJLm1EEEEvRNS_5tupleIJT_DpT0_EEENS_15__tuple_indicesIJXspT1_EEEE(__t=0x00007fb05a360120, (null)=__tuple_indices<1> @ 0x0000700000428ea0) + 40 at thread:337
    frame #9: 0x000000010771dc4d Realm`std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(__vp=0x00007fb05a360120) + 365 at thread:347
    frame #10: 0x000000010b1efc13 libsystem_pthread.dylib`_pthread_body + 131
    frame #11: 0x000000010b1efb90 libsystem_pthread.dylib`_pthread_start + 168
    frame #12: 0x000000010b1ed375 libsystem_pthread.dylib`thread_start + 13

  thread #11: tid = 0x30950d, 0x000000010b225386 libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.squareup.SocketRocket.NetworkThread'
    frame #0: 0x000000010b225386 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000010b2247c7 libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x0000000109f1eb64 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000109f1dfbf CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x0000000109f1d828 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x000000010965f2f1 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 267
    frame #6: 0x000000010734e759 Firebase`-[_FSRRunLoopThread main](self=0x00007fb059d054a0, _cmd=<unavailable>) + 238 at FSRWebSocket.m:1791 [opt]
    frame #7: 0x00000001096fcdfb Foundation`__NSThread__start__ + 1198
    frame #8: 0x000000010b1efc13 libsystem_pthread.dylib`_pthread_body + 131
    frame #9: 0x000000010b1efb90 libsystem_pthread.dylib`_pthread_start + 168
    frame #10: 0x000000010b1ed375 libsystem_pthread.dylib`thread_start + 13

  thread #12: tid = 0x309511, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #13: tid = 0x309515, 0x000000010b22b176 libsystem_kernel.dylib`__select + 10, name = 'com.apple.CFSocket.private'
    frame #0: 0x000000010b22b176 libsystem_kernel.dylib`__select + 10
    frame #1: 0x0000000109f641fa CoreFoundation`__CFSocketManager + 746
    frame #2: 0x000000010b1efc13 libsystem_pthread.dylib`_pthread_body + 131
    frame #3: 0x000000010b1efb90 libsystem_pthread.dylib`_pthread_start + 168
    frame #4: 0x000000010b1ed375 libsystem_pthread.dylib`thread_start + 13

* thread #14: tid = 0x30951a, 0x00000001079c60e7 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 295, queue = 'com.MyApp.database :: NSOperation 0x7fb05a7d5c10 (QOS: USER_INITIATED)'
    frame #0: 0x00000001079c60e7 Realm`realm::LinkListColumn::refresh_accessor_tree(unsigned long, realm::Spec const&) + 295
    frame #1: 0x0000000107a55738 Realm`realm::Table::refresh_column_accessors(unsigned long) + 632
    frame #2: 0x0000000107a6cb0a Realm`realm::Table::refresh_accessor_tree() + 666
    frame #3: 0x00000001079e06e8 Realm`realm::Group::advance_transact(unsigned long, unsigned long, realm::_impl::NoCopyInputStream&) + 600
  * frame #4: 0x00000001078e4e25 Realm`bool realm::SharedGroup::do_advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007fb05b083200, observer=0x00007000006343f8, version_id=(version = 18446744073709551615, index = 0), hist=0x00007fb05e8ab348)::TransactLogValidator*, realm::SharedGroup::VersionID, realm::_impl::History&) + 725 at group_shared.hpp:1060
    frame #5: 0x00000001078e4b32 Realm`void realm::SharedGroup::advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007fb05b083200, observer=0x00007000006343f8, version_id=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 402 at group_shared.hpp:930
    frame #6: 0x00000001078e498b Realm`void realm::_impl::SharedGroupFriend::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007fb05b083200, obs=0x00007000006343f8, ver=(version = 18446744073709551615, index = 0))::TransactLogValidator*, realm::SharedGroup::VersionID) + 59 at group_shared.hpp:1097
    frame #7: 0x00000001078e493b Realm`void realm::LangBindHelper::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007fb05b083200, observer=0x00007000006343f8, version=(version = 18446744073709551615, index = 0))::TransactLogValidator&&, realm::SharedGroup::VersionID) + 59 at lang_bind_helper.hpp:352
    frame #8: 0x00000001078e4865 Realm`auto realm::_impl::transaction::advance(this=0x00007000006343e8, args=0x00007000006343f8)::$_0::operator()<(anonymous namespace)::TransactLogValidator&>((anonymous namespace)::TransactLogValidator&&&) const + 69 at transact_log_handler.cpp:438
    frame #9: 0x00000001078e448c Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007000006343f8, context=0x00007fb05a31add0, sg=0x00007fb05b083200, func=0x00007000006343e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 1132 at transact_log_handler.cpp:222
    frame #10: 0x00000001078e3bfe Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007000006343f8, context=0x00007fb05a31add0, sg=0x00007fb05b083200, func=0x00007000006343e8, validate_schema_changes=true)::$_0>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SharedGroup::VersionID)::$_0&&, bool) + 62 at transact_log_handler.cpp:204
    frame #11: 0x00000001078e3baa Realm`realm::_impl::transaction::advance(sg=0x00007fb05b083200, context=0x00007fb05a31add0, version=(version = 18446744073709551615, index = 0)) + 90 at transact_log_handler.cpp:437
    frame #12: 0x00000001078de12a Realm`realm::Realm::refresh(this=0x00007fb05e846570) + 266 at shared_realm.cpp:409
    frame #13: 0x00000001078af08e Realm`-[RLMRealm refresh](self=0x00007fb05a35a850, _cmd="refresh") + 46 at RLMRealm.mm:595
    frame #14: 0x0000000107d6c42d RealmSwift`RealmSwift.Realm.refresh (self=0x00007fb05e848ec0)() -> Swift.Bool + 45 at Realm.swift:526
    frame #15: 0x0000000106c3fdc0 MyApp`MyApp.MyAppRelationOperation.realm.getter : RealmSwift.Realm(self=0x00007fb05a7d5c10) + 896 at MyAppRelationOperation.swift:24
    frame #16: 0x0000000106c4017c MyApp`MyApp.MyAppRelationOperation.main (self=0x00007fb05a7d5c10)() -> () + 44 at MyAppRelationOperation.swift:43
    frame #17: 0x0000000106c41442 MyApp`@objc MyApp.MyAppRelationOperation.main (MyApp.MyAppRelationOperation)() -> () + 34 at MyAppRelationOperation.swift:0
    frame #18: 0x0000000109605f8a Foundation`-[__NSOperationInternal _start:] + 646
    frame #19: 0x0000000109605b9b Foundation`__NSOQSchedule_f + 194
    frame #20: 0x000000010aeb749b libdispatch.dylib`_dispatch_client_callout + 8
    frame #21: 0x000000010ae9d8ec libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #22: 0x000000010ae9ce0d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #23: 0x000000010ae9fa56 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #24: 0x000000010ae9f4c5 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #25: 0x000000010b1ef68f libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #26: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13

  thread #15: tid = 0x30951b, 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x000000010b22b6de libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b1ef729 libsystem_pthread.dylib`_pthread_wqthread + 1283
    frame #2: 0x000000010b1ed365 libsystem_pthread.dylib`start_wqthread + 13
bdash commented 8 years ago

Thread 7 appears to be performing deallocations. It's possible that the timing was such that the deallocation of the Realm objects had already completed by the time the crash occurred, hiding them from the crash logs.

Legoless commented 8 years ago

Exactly. Is there any progress on this issue from your side?

jpsim commented 8 years ago

No progress to report on our side. We're still hoping someone will be able to share a sample project that can reproduce the issue. The one you shared with us at https://github.com/legoless/Sandbox hasn't triggered the assertion in my basic attempts to reproduce either.

Legoless commented 8 years ago

Okay @jpsim, I'll try more things with the sandbox project to see if I can get a reliably reproducable situation.

Legoless commented 8 years ago

@jpsim Do you have any other non-public contact, so I can share some more information?

bmunkholm commented 8 years ago

You can send confidential info to help@realm.io Thanks!

Legoless commented 8 years ago

Sent you an email. ;) Thanks!

bdash commented 8 years ago

Thanks for providing us with the project, @Legoless. I was able to easily follow your instructions and reproduce the issue. Some debugging confirms that a LinkView (the underlying type that represents a persisted List) is being accessed from a different thread than it was allocated on. This can result in the LinkView, and anything accessible from it, being mutated from multiple threads at once, and explains the variety of backtraces that this manifests with.

In the case of your application, the LinkView is escaping to a different thread as a result of there being a List property on an NSOperation subclass. The property is populated by the operation's main function, and released when the operation is deallocated. These two actions can happen on different threads. There's an easy fix though: the object property on your operation class is not used. Removing it prevents the List from escaping to a different thread.

bmunkholm commented 8 years ago

@bdash I assume you mean "can't" instead of "can" in "These two actions can happen on different threads."?

bdash commented 8 years ago

I mean can. The invocation of an NSOperation's -main function can, and frequently is, invoked on a different thread than the -dealloc of the same operation.

bdash commented 8 years ago

We should attempt to make destroying a LinkView from a different thread safe as it can be non-obvious to users why it's a problem, and it results in hard to debug crashes. I'll write up a core issue tracking that change. In the meantime, the workaround is to not let Lists or RLMArrays escape to different threads.

Legoless commented 8 years ago

I've deployed the workaround @bdash suggested which solves the crash for now. I'll keep on following issue, but it's not a high priority. Thanks for all help guys, awesome support from you! :)

bdash commented 8 years ago

It was made safe to destroy LinkViews from a different thread from the one they were created on in core v0.100, which was included in Realm Objective-C and Swift v0.101.0. I'll double-check with the test case that @Legoless provided to ensure that it has addressed this issue entirely.

bdash commented 8 years ago

This does appear to be fixed in v0.101.0.