Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-1629

Flexible sync: subscriptions.update crashes after 30 minutes or resuming dev work

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      How frequently does the bug occur?

      Sometimes

      Description

      Initializing realm subscriptions with flexible sync results in a crash either:

      • After about 30 minutes of using the app in simulator; or
      • When running the app in Xcode/Simulator for the first time after re-starting work on the app (I.e. we closed Xcode and simulator for the day and started up again the next day).

      This crash seems similar to the bug being experienced over here in the JS library.

      Stacktrace & log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Realm is logged in
      (lldb) bt
      * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
        * frame #0: 0x0000000102c52164 Check Writer`realm::sync::Session::on_new_flx_sync_subscription(this=0x0000000000000000, new_version=11) at client.cpp:1584:5
          frame #1: 0x0000000102a77ac8 Check Writer`realm::SyncSession::make_flx_subscription_store(this=0x0000600003532038, new_version=11)::$_2::operator()(long long) const at sync_session.cpp:259:20
          frame #2: 0x0000000102a77a38 Check Writer`void realm::util::UniqueFunction<void (long long)>::call_regular_void<realm::SyncSession::make_flx_subscription_store(is_void=std::__1::true_type @ 0x000000016dc4114f, f=0x0000600003532038, args=0x000000016dc411c0)::$_2>(std::__1::integral_constant<bool, true>, realm::SyncSession::make_flx_subscription_store()::$_2&, long long&&) at functional.hpp:148:9
          frame #3: 0x0000000102a77998 Check Writer`realm::util::UniqueFunction<void (long long)>::SpecificImpl<realm::SyncSession::make_flx_subscription_store(this=0x0000600003532030, args=0x000000016dc411c0)::$_2>::call(long long&&) at functional.hpp:168:20
          frame #4: 0x0000000102d22b9c Check Writer`realm::util::UniqueFunction<void (long long)>::operator(this=0x00006000008313e8, args=11)(long long) const at functional.hpp:94:22
          frame #5: 0x0000000102d22a3c Check Writer`realm::sync::MutableSubscriptionSet::commit(this=0x0000600000235140) && at subscriptions.cpp:475:9
          frame #6: 0x00000001024d60c4 Check Writer`-[RLMSyncSubscriptionSet write:onComplete:](self=0x0000600001c1f640, _cmd="write:onComplete:", block=0x0000000102623a60, completionBlock=0x00000001024ff748) at RLMSyncSubscription.mm:243:111
          frame #7: 0x00000001026239ac Check Writer`SyncSubscriptionSet.write(block=0x0000000102223d60 Check Writer`partial apply forwarder for closure #1 () -> () in Check_Writer.AccountList.setSubscription() -> () at <compiler-generated>, onComplete=nil, self=RealmSwift.SyncSubscriptionSet @ 0x000000016dc418b8) at SyncSubscription.swift:203:32
          frame #8: 0x000000010221edb4 Check Writer`AccountList.setSubscription(self=Check_Writer.AccountList @ 0x0000000123e0ea80) at AccountList.swift:63:23
          frame #9: 0x000000010221ece4 Check Writer`implicit closure #2 in implicit closure #1 in AccountList.body.getter(self=Check_Writer.AccountList @ 0x0000000123e0ea80) at AccountList.swift:58:28
          frame #10: 0x00000001b9b2d924 SwiftUI`closure #1 () -> () in SwiftUI._AppearanceActionModifier.MergedBox.update() -> () + 92
          frame #11: 0x00000001b9c9518c SwiftUI`reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @escaping @callee_guaranteed () -> (@out ()) + 20
          frame #12: 0x00000001ba1a0124 SwiftUI`closure #1 () -> () in SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 2256
          frame #13: 0x00000001ba198c7c SwiftUI`SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 348
          frame #14: 0x00000001ba3d75f4 SwiftUI`SwiftUI._UIHostingView.layoutSubviews() -> () + 248
          frame #15: 0x00000001ba3d765c SwiftUI`@objc SwiftUI._UIHostingView.layoutSubviews() -> () + 24
          frame #16: 0x00000001852ea564 UIKitCore`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2588
          frame #17: 0x0000000188513848 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 472
          frame #18: 0x000000018851e654 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 116
          frame #19: 0x0000000188457538 QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 448
          frame #20: 0x0000000188483564 QuartzCore`CA::Transaction::commit() + 696
          frame #21: 0x0000000184d991e8 UIKitCore`__34-[UIApplication _firstCommitBlock]_block_invoke_2 + 40
          frame #22: 0x0000000180360580 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
          frame #23: 0x000000018035f854 CoreFoundation`__CFRunLoopDoBlocks + 408
          frame #24: 0x000000018035a018 CoreFoundation`__CFRunLoopRun + 764
          frame #25: 0x0000000180359804 CoreFoundation`CFRunLoopRunSpecific + 572
          frame #26: 0x000000018c23660c GraphicsServices`GSEventRunModal + 160
          frame #27: 0x0000000184d7bd2c UIKitCore`-[UIApplication _run] + 992
          frame #28: 0x0000000184d808c8 UIKitCore`UIApplicationMain + 112
          frame #29: 0x00000001ba1f7564 SwiftUI`closure #1 (Swift.UnsafeMutablePointer<Swift.Optional<Swift.UnsafeMutablePointer<Swift.Int8>>>) -> Swift.Never in SwiftUI.KitRendererCommon(Swift.AnyObject.Type) -> Swift.Never + 160
          frame #30: 0x00000001ba1f74c0 SwiftUI`SwiftUI.runApp<τ_0_0 where τ_0_0: SwiftUI.App>(τ_0_0) -> Swift.Never + 164
          frame #31: 0x00000001b9c2aadc SwiftUI`static SwiftUI.App.main() -> () + 80
          frame #32: 0x00000001021fac8c Check Writer`static CheckWriterApp.$main(self=Check_Writer.CheckWriterApp) at CheckWriterApp.swift:13:1
          frame #33: 0x00000001021fae54 Check Writer`main at CheckWriterApp.swift:0
          frame #34: 0x0000000105d71cd8 dyld_sim`start_sim + 20
          frame #35: 0x0000000105bb90f4 dyld`start + 520
      (lldb)
      

      Can you reproduce the bug?

      Yes, sometimes

      Reproduction Steps

      1. Setting up a subscription after the UI appears, I.e.:
      .onAppear(perform: setSubscription)
      
      private func setSubscription() {
        let subscriptions = realm.subscriptions
        subscriptions.write {
            if let currentSubscription = subscriptions.first(named: "bankAccountList") {
                print("Replacing subscription for bankAccountList")
                currentSubscription.update(toType: BankAccount.self) { bankAccount in
                    bankAccount._id != nil
                }
            } else {
                print("Appending subscription for bankAccountList")
                subscriptions.append(QuerySubscription<BankAccount>(name: "bankAccountList") { bankAccount in
                    bankAccount._id != nil
                })
            }
          }
        }
      
      1. Run the application in Xcode
      2. Stop the application in Xcode
      3. Quit Xcode
      4. Wait about 30 to 60 minutes.
      5. Re-open the Xcode project
      6. Run the application in Xcode
      7. The crash will happen when the application appears in the simulator
      8. Stop the application in Xcode
      9. Delete the application from the iOS Simulator
      10. Run the application in Xcode
      11. All authentication will be wiped out, but the application will work again.

      Version

      10.24.1

      What SDK flavour are you using?

      MongoDB Realm (i.e. Sync, auth, functions)

      Are you using encryption?

      No, not using encryption

      Platform OS and version(s)

      iOS Simulator (iPhone 12, iOS 15.4)

      Build environment

      Xcode version: 13.3 (13E113)
      Dependency manager and version: Swift Package Manager built into Xcode 13.3 (using package version 10.24.1)

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: