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

Crash at 'realm::Transaction::Transaction'

      How frequently does the bug occur?

      Sometimes

      Description

      Hi, I used the code as follows:

              self.dbSemaphore.wait()
              autoreleasepool {
                  var rlm: Realm? = nil
                  do {
                      rlm = try Realm(configuration: self.configuration)
                      
                      try rlm?.safeWrite {
                          rlm?.create(type, value: obj, update: .modified)
                      }
                      
                      if frozenRealm {
                          self.freezeSemaphore.wait()
                          self.frozenRealm = rlm?.freeze()
                          self.freezeSemaphore.signal()
                      }
                  } catch {
                      KNMapLogger.log.error("Failed to open or write to the Realm DB.")
                  }
              }
              self.dbSemaphore.signal()
      

      It's hard to reproduce in the test and crashes occur with a very low probability.

      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
      Crashed: NSOperationQueue 0x153d816f0 (QOS: UNSPECIFIED)
      0  Realm                          0x2c2408 realm::Transaction::Transaction(std::__1::shared_ptr<realm::DB>, realm::SlabAlloc*, realm::DB::ReadLockInfo&, realm::DB::TransactStage) + 272
      1  Realm                          0x198764 std::__1::shared_ptr<realm::Transaction> (anonymous namespace)::make_transaction_ref<std::__1::shared_ptr<realm::DB>, realm::SlabAlloc*, realm::DB::ReadLockInfo&, realm::DB::TransactStage>(std::__1::shared_ptr<realm::DB>&&, realm::SlabAlloc*&&, realm::DB::ReadLockInfo&, realm::DB::TransactStage&&) + 88
      2  Realm                          0x19898c realm::DB::start_frozen(realm::VersionID) + 276
      3  Realm                          0x4747ec realm::Realm::begin_read(realm::VersionID) + 52
      4  Realm                          0x4746e4 realm::Realm::transaction() + 108
      5  Realm                          0x12a0e4 -[RLMRealm frozenCopy] + 188
      6  Realm                          0x12e2fc RLMGetFrozenRealmForSourceRealm(RLMRealm*) + 276
      7  KNSDK                          0x2a8518 specialized closure #1 in KNMapGatewayRLM.insertData<A>(obj:type:primaryKey:frozenRealm:) + 16764
      8  KNSDK                          0x2a81a0 specialized KNMapGatewayRLM.insertData<A>(obj:type:primaryKey:frozenRealm:) + 15876
      9  KNSDK                          0x2a776c KNMapAttributeGatewayRLM.insertMapAttribute(arg:completion:) + 122 (KNMapAttributeGatewayRLM.swift:122)
      10 KNSDK                          0x2a7e84 protocol witness for KNGatewayRLM.insertData(arg:completion:) in conformance KNMapAttributeGatewayRLM + 15080 (<compiler-generated>:15080)
      11 KNSDK                          0x1acf78 closure #2 in closure #1 in KNMapLoaderRLM.retrieveDataRLMO(arg:completion:) + 16480
      12 KNSDK                          0x1b752c partial apply for closure #2 in closure #1 in KNMapLoaderRLM.retrieveDataRLMO(arg:completion:) + 372 (<compiler-generated>:372)
      13 KNSDK                          0x1aeb70 specialized closure #1 in KNLoader.downloadMapData(url:reqType:md5:retryCnt:completion:) + 23640
      14 KNSDK                          0x1b83f4 partial apply for specialized closure #1 in KNLoader.downloadMapData(url:reqType:md5:retryCnt:completion:) + 4156 (<compiler-generated>:4156)
      15 KNSDK                          0x1aef10 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed KNError?) -> () + 24568 (<compiler-generated>:24568)
      16 KNSDK                          0x354fc __75-[KNHttpRequest requestWithHttpMethod:suspendOthers:urlSession:dateOrigin:]_block_invoke + 289 (KNHttpRequest.m:289)
      17 Foundation                     0xa6f14 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24
      18 Foundation                     0x7b020 -[NSBlockOperation main] + 104
      19 Foundation                     0x7afb0 __NSOPERATION_IS_INVOKING_MAIN__ + 16
      20 Foundation                     0x3c4d8 -[NSOperation start] + 708
      21 Foundation                     0x3c20c __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 16
      22 Foundation                     0x4189c __NSOQSchedule_f + 172
      23 libdispatch.dylib              0x12fc4 _dispatch_block_async_invoke2 + 148
      24 libdispatch.dylib              0x3eac _dispatch_client_callout + 20
      25 libdispatch.dylib              0x7330 _dispatch_continuation_pop + 504
      26 libdispatch.dylib              0x6998 _dispatch_async_redirect_invoke + 584
      27 libdispatch.dylib              0x15944 _dispatch_root_queue_drain + 396
      28 libdispatch.dylib              0x16158 _dispatch_worker_thread2 + 164
      29 libsystem_pthread.dylib        0xda0 _pthread_wqthread + 228
      30 libsystem_pthread.dylib        0xb7c start_wqthread + 8
      

      Can you reproduce the bug?

      No

      Reproduction Steps

      No response

      Version

      10.38.3

      What Atlas Services are you using?

      Local Database only

      Are you using encryption?

      Yes

      Platform OS and version(s)

      iOS 16.5.0, 16.0.0, 16.3.1

      Build environment

      Xcode version: ...
      Dependency manager and version: ...

            Assignee:
            lee.maguire@mongodb.com Lee Maguire
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: