Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2567

App crash on launch when realm-js is installed on an app with an existing RealmSwift instance

      How frequently does the bug occur?

      Always

      Description

      We have an iOS app that was initially written in Swift/SwiftUI and we are slowly adding React Native components. The app has a working Realm DB on the swift side and we were looking to create a separate Realm instance on RN/JS side. As the first steps, we ran

      • yarn add @realm/react realm
      • pod install

      We haven't created the Realm instance on JS side yet and the app crashes on launch. It seems whenever the original Realm DB is queried/used, the app crashes. (Stacktrace of one of the crashes are attached; "Access to invalidated Results objects." is the message of exception.)

      One data point: I looked into the realm-JS source (RealmReact.mm) because I suspected that some initialization code on the JS side is changing the underlying state of RealmSwift/RealmCore since we haven't even instantiated any Realm DB on the JS side yet. Returning early in setBridge without calling realm_jsi_init does seem to address the crash, which agrees with my hypothesis about Realm-JS initialization stepping on the internal state of Realm somehow.

      The question is, does Realm support the coexistence of RealmJS and RealmSwift? Or are we doing something that's not officially supported? We might have to look into alternative solutions if this use case is not supported and any response would be appreciated!

      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
      Exception	NSException *	"Access to invalidated Results objects"	0x0000600003c36760
      
      Thread#0	0x0000000180437324 in __exceptionPreprocess ()
      #1	0x0000000180051274 in objc_exception_throw ()
      #2	0x00000001010d0aa4 in RLMThrowCollectionException(NSString*) at /Users/daniel/Library/Developer/Xcode/DerivedData/GolfApp-eajrvxjumwmwyxdmtpptomrlptrr/SourcePackages/checkouts/realm-swift/Realm/RLMResults.mm:94
      #3	0x00000001010d4890 in auto translateCollectionError<-[RLMResults count]::$_1>(-[RLMResults count]::$_1&&, NSString*) at /Users/daniel/Library/Developer/Xcode/DerivedData/GolfApp-eajrvxjumwmwyxdmtpptomrlptrr/SourcePackages/checkouts/realm-swift/Realm/RLMResults_Private.hpp:63
      #4	0x00000001010d0da8 in auto translateErrors<-[RLMResults count]::$_1>(-[RLMResults count]::$_1&&) [inlined] at /Users/daniel/Library/Developer/Xcode/DerivedData/GolfApp-eajrvxjumwmwyxdmtpptomrlptrr/SourcePackages/checkouts/realm-swift/Realm/RLMResults.mm:104
      #5	0x00000001010d0d98 in -[RLMResults count] at /Users/daniel/Library/Developer/Xcode/DerivedData/GolfApp-eajrvxjumwmwyxdmtpptomrlptrr/SourcePackages/checkouts/realm-swift/Realm/RLMResults.mm:140
      #6	0x0000000101a553b4 in RealmCollectionImpl.count.getter at /Users/daniel/Library/Developer/Xcode/DerivedData/GolfApp-eajrvxjumwmwyxdmtpptomrlptrr/SourcePackages/checkouts/realm-swift/RealmSwift/Impl/RealmCollectionImpl.swift:37
      #7	0x00000001009cf254 in closure #1 in closure #1 in TimeSummaryView.body.getter at /Users/daniel/source/SwingTuneUp-RN/ios/SwingCamApp/Views/Diary/PageContent/TimeSummaryView.swift:69
      #8	0x00000001009d9f10 in partial apply for closure #1 in closure #1 in TimeSummaryView.body.getter ()
      #9	0x0000000113afd4d0 in VStack.init(alignment:spacing:content:) ()
      #10	0x00000001009ce3f4 in closure #1 in TimeSummaryView.body.getter at /Users/daniel/source/SwingTuneUp-RN/ios/SwingCamApp/Views/Diary/PageContent/TimeSummaryView.swift:63
      #11	0x00000001009cea28 in partial apply for closure #1 in TimeSummaryView.body.getter ()
      #12	0x0000000113ab1460 in ___lldb_unnamed_symbol171276 ()
      #13	0x0000000113777238 in ___lldb_unnamed_symbol143524 ()
      #14	0x00000001137758cc in ___lldb_unnamed_symbol143414 ()
      #15	0x0000000113ab03f8 in ___lldb_unnamed_symbol171219 ()
      #16	0x00000001132aba00 in ___lldb_unnamed_symbol103442 ()
      #17	0x000000019d23fe34 in AG::Graph::UpdateStack::update() ()
      #18	0x000000019d240534 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
      #19	0x000000019d24d7a4 in AG::Subgraph::update(unsigned int) ()
      #20	0x0000000113f84c40 in ___lldb_unnamed_symbol211982 ()
      #21	0x0000000113e002d0 in ___lldb_unnamed_symbol199705 ()
      #22	0x0000000113df90f4 in ___lldb_unnamed_symbol199511 ()
      #23	0x000000011348a25c in ___lldb_unnamed_symbol119695 ()
      #24	0x00000001141628e0 in ___lldb_unnamed_symbol228118 ()
      #25	0x000000010a710528 in _dispatch_call_block_and_release ()
      #26	0x000000010a711d50 in _dispatch_client_callout ()
      #27	0x000000010a722808 in _dispatch_main_queue_drain ()
      #28	0x000000010a7222d4 in _dispatch_main_queue_callback_4CF ()
      #29	0x000000018039a784 in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
      #30	0x0000000180394de4 in __CFRunLoopRun ()
      #31	0x0000000180394254 in CFRunLoopRunSpecific ()
      #32	0x0000000188eb7c9c in GSEventRunModal ()
      #33	0x000000010f9caff0 in -[UIApplication _run] ()
      #34	0x000000010f9cef3c in UIApplicationMain ()
      #35	0x0000000113e7f34c in ___lldb_unnamed_symbol203070 ()
      #36	0x0000000113e7f1ec in ___lldb_unnamed_symbol203068 ()
      #37	0x0000000113677474 in static App.main() ()
      #38	0x0000000100879cc4 in static SwingCamApp.$main() at /Users/daniel/source/SwingTuneUp-RN/ios/SwingCamApp/SwingCamApp.swift:82
      #39	0x0000000100879f0c in main ()
      #40	0x00000001098c1514 in start_sim ()
      #41	0x0000000109989f28 in start ()
      #42	0x9871000000000000 in 0x9871000000000000 ()
      

      Can you reproduce the bug?

      Always

      Reproduction Steps

      App crashes on launch

      Version

      realm: 12.1.0 @realm/react 0.6.0

      What services are you using?

      Local Database only

      Are you using encryption?

      No

      Platform OS and version(s)

      iOS 16,

      Build environment

      React-native: 0.71.7
      Xcode: 14.3.1
      iOS: 16.4 (Simulator)

      Cocoapods version

      1.12.1

            Assignee:
            linnea.jansson@mongodb.com Linnea Enoh Jansson (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: