Couchbase Lite 2.0 Database and its document not cleared on logout iOS


#21

Removing the listener frequently should not do any harm.


#22

I have added document listener on flight id ( of document type : flight) , since there are multiple flights which i need to observe so first i add listener and then store listnertoken of ListenerToken in model array and when the flights time is over then i try to remove it through database.document.removelistener(documentlistenertoken) and i properly check documentlistenertoken is not nil , but when i create and remove it frequently as flights depart or new flights arrive then i am facing crash, kindly help ( since without handling listener token i can’t close database properly ) , i am attaching screenshot of the crash and log is also :

Backtrace log is here :

Crash backtrace log

  • thread #1, queue = ‘com.apple.main-thread’, stop reason = EXC_BAD_ACCESS (code=1, address=0x600008400000)

  • frame #0: 0x0000000111b6ece0 CouchbaseLiteSwift`litecore::SequenceTracker::removeDocChangeNotifier(std::__1::__list_const_iterator<litecore::SequenceTracker::Entry, void*>, litecore::DocChangeNotifier*) [inlined] std::__1::__wrap_iter<litecore::DocChangeNotifier**> std::__1::find<std::__1::__wrap_iter<litecore::DocChangeNotifier**>, litecore::DocChangeNotifier*>(std::__1::__wrap_iter<litecore::DocChangeNotifier**>, std::__1::__wrap_iter<litecore::DocChangeNotifier**>, litecore::DocChangeNotifier* const&) at algorithm:997 [opt]

frame #1: 0x0000000111b6ecd4 CouchbaseLiteSwift`litecore::SequenceTracker::removeDocChangeNotifier(this=0x00006000001b6880, entry=<unavailable>, notifier=0x00006040006dcbf0) at SequenceTracker.cc:295 [opt]

frame #2: 0x0000000111afb8ba CouchbaseLiteSwift`::c4docobs_free(C4DocumentObserver *) [inlined] litecore::DocChangeNotifier::~DocChangeNotifier(this=<unavailable>) at SequenceTracker.hh:167 [opt]

frame #3: 0x0000000111afb8ad CouchbaseLiteSwift`::c4docobs_free(C4DocumentObserver *) [inlined] litecore::DocChangeNotifier::~DocChangeNotifier(this=<unavailable>) at SequenceTracker.hh:166 [opt]

frame #4: 0x0000000111afb8ad CouchbaseLiteSwift`::c4docobs_free(C4DocumentObserver *) [inlined] c4DocumentObserver::~c4DocumentObserver(this=<unavailable>) at c4Observer.cc:107 [opt]

frame #5: 0x0000000111afb8a9 CouchbaseLiteSwift`::c4docobs_free(C4DocumentObserver *) [inlined] c4DocumentObserver::~c4DocumentObserver() at c4Observer.cc:107 [opt]

frame #6: 0x0000000111afb8a9 CouchbaseLiteSwift`::c4docobs_free(obs=0x00006040006dcbd0) at c4Observer.cc:147 [opt]

frame #7: 0x0000000111aa0019 CouchbaseLiteSwift`::-[CBLDocumentChangeNotifier stop](self=0x0000604007057ac0, _cmd=<unavailable>) at CBLDocumentChangeNotifier.mm:60 [opt]

frame #8: 0x0000000111ab1f84 CouchbaseLiteSwift`::-[CBLDatabase removeDocumentChangeListenerWithToken:](self=<unavailable>, _cmd=<unavailable>, token=<unavailable>) at CBLDatabase.mm:728 [opt]

frame #9: 0x0000000111ab0c66 CouchbaseLiteSwift`::-[CBLDatabase removeChangeListenerWithToken:](self=<unavailable>, _cmd=<unavailable>, token=<unavailable>) at CBLDatabase.mm:452 [opt]

frame #10: 0x0000000111a7bc63 CouchbaseLiteSwift`CouchbaseLiteSwift.Database.removeChangeListener(withToken: CouchbaseLiteSwift.ListenerToken) -> () at Database.swift:279

frame #11: 0x000000011084e48a Insight`CouchbaseAdapter.removeNDNAPDListener(self=0x000060c0001f9000) at CouchbaseAdapter+Ext.swift:1295

frame #12: 0x00000001101bbb11 Insight`GateCardVC.viewWillDisappear(animated=false, self=0x00007fe93ec4c000) at GateCardVC.swift:193

frame #13: 0x00000001101bbb63 Insight`@objc GateCardVC.viewWillDisappear(_:slight_smile: at GateCardVC.swift:0

frame #14: 0x00000001155f3ec9 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 803

frame #15: 0x00000001155f4747 UIKit`-[UIViewController __viewWillDisappear:] + 95

frame #16: 0x00000001156362a1 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 3647

frame #17: 0x000000011563661e UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 870

frame #18: 0x000000011563786c UIKit`-[UINavigationController __viewWillLayoutSubviews] + 150

frame #19: 0x000000011588fd0b UIKit`-[UILayoutContainerView layoutSubviews] + 231

frame #20: 0x00000001155197a8 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515

frame #21: 0x0000000115283456 QuartzCore`-[CALayer layoutSublayers] + 177

frame #22: 0x0000000115287667 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 395

frame #23: 0x000000011520e0fb QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 343

frame #24: 0x000000011523b79c QuartzCore`CA::Transaction::commit() + 568

frame #25: 0x000000011523c51a QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 76

frame #26: 0x000000011450e607 CoreFoundation`CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23

frame #27: 0x000000011450e55e CoreFoundation`__CFRunLoopDoObservers + 430

frame #28: 0x00000001144f2b81 CoreFoundation`__CFRunLoopRun + 1537

frame #29: 0x00000001144f230b CoreFoundation`CFRunLoopRunSpecific + 635

frame #30: 0x000000011af01a73 GraphicsServices`GSEventRunModal + 62

frame #31: 0x000000011544a057 UIKit`UIApplicationMain + 159

frame #32: 0x000000010ffc7297 Insight`main at AppDelegate.swift:25

frame #33: 0x0000000118215955 libdyld.dylib`start + 1

frame #34: 0x0000000118215955 libdyld.dylib`start + 1


#23

Coincidentally this bug was discovered today before you posted this message. It was also fixed. It will be in the next release in a few months.


#24

Sorry about the bug — until this is fixed, I would avoid using document listeners if they’d be frequently removed. Instead you can use a database listener, which will notify you about all documents. Then you can do something like keep a Dictionary to map docIDs to listener blocks.