Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-743

Crash when counting items

      SDK and version

      SDK : Cocoa
      Version: 10.7.6

      Observations

      • Happened during tests
      • Not sure if it's always reproducible, it just happened

      Crash log / stacktrace

      >/Users/florentin/Library/Developer/Xcode/DerivedData/kDrive-glnhbfgghgjablbwsbggafptflzt/SourcePackages/checkouts/realm-core/src/realm/array.hpp:891: [realm-core-10.7.2] Assertion failed: m_has_refs
      0 kDriveCore 0x0000000104864f64 ZN5realm4utilL18terminate_internalERNSt3_118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
      1 kDriveCore 0x00000001048651c8 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 240
      2 kDriveCore 0x00000001044ce6ac _ZNK5realm5Array10get_as_refEm + 188
      3 kDriveCore 0x00000001045490b0 _ZN5realm16ClusterNodeInner4initENS_6MemRefE + 104
      4 kDriveCore 0x000000010454bf40 _ZNK5realm16ClusterNodeInner8traverseENS_4util11FunctionRefIFbPKNS_7ClusterEEEEx + 560
      5 kDriveCore 0x000000010454e40c _ZNK5realm11ClusterTree8traverseENS_4util11FunctionRefIFbPKNS_7ClusterEEEE + 164
      6 kDriveCore 0x00000001046948c0 _ZNK5realm5Table17traverse_clustersENS_4util11FunctionRefIFbPKNS_7ClusterEEEE + 60
      7 kDriveCore 0x000000010469541c _ZNK5realm5Query8do_countEm + 740
      8 kDriveCore 0x00000001046959cc _ZN5realm5Query5countERKNS_18DescriptorOrderingE + 208
      9 kDriveCore 0x00000001041f0a18 _ZN5realm7Results7do_sizeEv + 316
      10 kDriveCore 0x00000001041fce84 _ZN5realm7Results4sizeEv + 52
      11 kDriveCore 0x0000000103fd9974 _ZZ19-[RLMResults count]ENK3$_1clEv + 36
      12 kDriveCore 0x0000000103fd5750 _ZL25translateRLMResultsErrorsIZ19-[RLMResults count]E3$_1EDaOT_P8NSString + 36
      13 kDriveCore 0x0000000103fd5720 -[RLMResults count] + 44
      14 kDriveCore 0x00000001040b3f00 $s10RealmSwift7ResultsV5countSivg + 56
      15 kDriveCore 0x0000000103a66378 $s10kDriveCore11UploadQueueC07publishC5Count33_1F4ACEEFA41435518ABA99BB68BF9E9ELL10withParent5usingySi_10RealmSwift0P0VtF + 140
      16 kDriveCore 0x0000000103a662dc $s10kDriveCore11UploadQueueC05addToD033_1F4ACEEFA41435518ABA99BB68BF9E9ELL4file5usingyAA0C4FileC_10RealmSwift0P0VtFyycfU0_yALXEfU_ + 68
      17 kDriveCore 0x0000000103990fd4 $s10kDriveCore15BackgroundRealmC7executeyyy0D5Swift0D0VXEFyyXEfU_yyXEfU_ + 88
      18 kDriveCore 0x0000000103991004 $ss5Error_pIgzo_ytsAA_pIegrzo_TR + 24
      19 kDriveCore 0x0000000103991114 $ss5Error_pIgzo_ytsAA_pIegrzo_TRTA + 28
      20 libswiftObjectiveC.dylib 0x00000001c3f2af24 $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 64
      21 kDriveCore 0x0000000103990e74 $s10kDriveCore15BackgroundRealmC7executeyyy0D5Swift0D0VXEFyyXEfU_ + 180
      22 kDriveCore 0x0000000103990a54 $sIg_Ieg_TR + 20
      23 kDriveCore 0x0000000103990aac $sIeg_IyB_TR + 24
      24 libdispatch.dylib 0x000000010367dde0 _dispatch_client_callout + 20
      25 libdispatch.dylib 0x000000010368f0a8 _dispatch_lane_barrier_sync_invoke_and_complete + 176
      26 kDriveCore 0x0000000103990d68 $s10kDriveCore15BackgroundRealmC7executeyyy0D5Swift0D0VXEF + 336
      27 kDriveCore 0x0000000103a66278 $s10kDriveCore11UploadQueueC05addToD033_1F4ACEEFA41435518ABA99BB68BF9E9ELL4file5usingyAA0C4FileC_10RealmSwift0P0VtFyycfU0_ + 364
      28 kDriveCore 0x0000000103975d80 $sIeg_IeyB_TR + 52
      29 Foundation 0x000000019edc7e08 0D9893A4-5804-3F0D-BB3F-73989EA36AD3 + 1248776
      30 libdispatch.dylib 0x000000010367c0b4 _dispatch_call_block_and_release + 32
      31 libdispatch.dylib 0x000000010367dde0 _dispatch_client_callout + 20
      32 libdispatch.dylib 0x0000000103680918 _dispatch_queue_override_invoke + 1008
      33 libdispatch.dylib 0x0000000103691e30 _dispatch_root_queue_drain + 396
      34 libdispatch.dylib 0x00000001036927ec _dispatch_worker_thread2 + 136
      35 libsystem_pthread.dylib 0x00000001e95a2768 _pthread_wqthread + 216
      36 libsystem_pthread.dylib 0x00000001e95a974c start_wqthread + 8!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2021-06-17 15:16:10.103745+0200 kDrive[59930:12251347] /Users/florentin/Library/Developer/Xcode/DerivedData/kDrive-glnhbfgghgjablbwsbggafptflzt/SourcePackages/checkouts/realm-core/src/realm/array.hpp:891: [realm-core-10.7.2] Assertion failed: m_has_refs
      0 kDriveCore 0x0000000104864f64 ZN5realm4utilL18terminate_internalERNSt3_118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
      1 kDriveCore 0x00000001048651c8 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 240
      2 kDriveCore 0x00000001044ce6ac _ZNK5realm5Array10get_as_refEm + 188
      3 kDriveCore 0x00000001045490b0 _ZN5realm16ClusterNodeInner4initENS_6MemRefE + 104
      4 kDriveCore 0x000000010454bf40 _ZNK5realm16ClusterNodeInner8traverseENS_4util11FunctionRefIFbPKNS_7ClusterEEEEx + 560
      5 kDriveCore 0x000000010454e40c _ZNK5realm11ClusterTree8traverseENS_4util11FunctionRefIFbPKNS_7ClusterEEEE + 164
      6 kDriveCore 0x00000001046948c0 _ZNK5realm5Table17traverse_clustersENS_4util11FunctionRefIFbPKNS_7ClusterEEEE + 60
      7 kDriveCore 0x000000010469541c _ZNK5realm5Query8do_countEm + 740
      8 kDriveCore 0x00000001046959cc _ZN5realm5Query5countERKNS_18DescriptorOrderingE + 208
      9 kDriveCore 0x00000001041f0a18 _ZN5realm7Results7do_sizeEv + 316
      10 kDriveCore 0x00000001041fce84 _ZN5realm7Results4sizeEv + 52
      11 kDriveCore 0x0000000103fd9974 _ZZ19-[RLMResults count]ENK3$_1clEv + 36
      12 kDriveCore 0x0000000103fd5750 _ZL25translateRLMResultsErrorsIZ19-[RLMResults count]E3$_1EDaOT_P8NSString + 36
      13 kDriveCore 0x0000000103fd5720 -[RLMResults count] + 44
      14 kDriveCore 0x00000001040b3f00 $s10RealmSwift7ResultsV5countSivg + 56
      15 kDriveCore 0x0000000103a66378 $s10kDriveCore11UploadQueueC07publishC5Count33_1F4ACEEFA41435518ABA99BB68BF9E9ELL10withParent5usingySi_10RealmSwift0P0VtF + 140
      16 kDriveCore 0x0000000103a662dc $s10kDriveCore11UploadQueueC05addToD033_1F4ACEEFA41435518ABA99BB68BF9E9ELL4file5usingyAA0C4FileC_10RealmSwift0P0VtFyycfU0_yALXEfU_ + 68
      17 kDriveCore 0x0000000103990fd4 $s10kDriveCore15BackgroundRealmC7executeyyy0D5Swift0D0VXEFyyXEfU_yyXEfU_ + 88
      18 kDriveCore 0x0000000103991004 $ss5Error_pIgzo_ytsAA_pIegrzo_TR + 24
      19 kDriveCore 0x0000000103991114 $ss5Error_pIgzo_ytsAA_pIegrzo_TRTA + 28
      20 libswiftObjectiveC.dylib 0x00000001c3f2af24 $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 64
      21 kDriveCore 0x0000000103990e74 $s10kDriveCore15BackgroundRealmC7executeyyy0D5Swift0D0VXEFyyXEfU_ + 180
      22 kDriveCore 0x0000000103990a54 $sIg_Ieg_TR + 20
      23 kDriveCore 0x0000000103990aac $sIeg_IyB_TR + 24
      24 libdispatch.dylib 0x000000010367dde0 _dispatch_client_callout + 20
      25 libdispatch.dylib 0x000000010368f0a8 _dispatch_lane_barrier_sync_invoke_and_complete + 176
      26 kDriveCore 0x0000000103990d68 $s10kDriveCore15BackgroundRealmC7executeyyy0D5Swift0D0VXEF + 336
      27 kDriveCore 0x0000000103a66278 $s10kDriveCore11UploadQueueC05addToD033_1F4ACEEFA41435518ABA99BB68BF9E9ELL4file5usingyAA0C4FileC_10RealmSwift0P0VtFyycfU0_ + 364
      28 kDriveCore 0x0000000103975d80 $sIeg_IeyB_TR + 52
      29 Foundation 0x000000019edc7e08 0D9893A4-5804-3F0D-BB3F-73989EA36AD3 + 1248776
      30 libdispatch.dylib 0x000000010367c0b4 _dispatch_call_block_and_release + 32
      31 libdispatch.dylib 0x000000010367dde0 _dispatch_client_callout + 20
      32 libdispatch.dylib 0x0000000103680918 _dispatch_queue_override_invoke + 1008
      33 libdispatch.dylib 0x0000000103691e30 _dispatch_root_queue_drain + 396
      34 libdispatch.dylib 0x00000001036927ec _dispatch_worker_thread2 + 136
      35 libsystem_pthread.dylib 0x00000001e95a2768 _pthread_wqthread + 216
      36 libsystem_pthread.dylib 0x00000001e95a974c start_wqthread + 8!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

      Steps & Code to Reproduce

      Happened on an upload queue. Here is a simplified set up:
      ```swift
      class UploadQueue {
      private let dispatchQueue = DispatchQueue(label: "upload-sync")

      private(set) lazy var operationQueue: OperationQueue = {
          let queue = OperationQueue()
          queue.qualityOfService = .userInitiated
          queue.maxConcurrentOperationCount = 4
          queue.isSuspended = shouldSuspendQueue
          return queue
      }()
      private var realm: Realm!
      
      // Note: UploadFile is a Realm object
      func addToQueue(file: UploadFile) {
          dispatchQueue.async {
              autoreleasepool {
                  try? realm.safeWrite {
                      realm.add(file, update: .modified)
                  }
      
                  let operation = UploadOperation(file: file)
                  operation.queuePriority = file.priority
                  operation.completionBlock = { [parentId = file.parentDirectoryId] in
                      BackgroundRealm.uploads.execute { realm in
                          let uploadCount = getUploadingFiles(withParent: parentId, using: realm).count // crashed here
                          // Using uploadCount…
                      }
                  }
              }
          }
      }
      

      }

      class BackgroundRealm {

      public static let uploads = getQueue(for: DriveFileManager.constants.uploadsRealmConfiguration)
      private static var instances: [String: BackgroundRealm] = [:]
      
      private let realm: Realm
      private let queue: DispatchQueue
      
      class func getQueue(for configuration: Realm.Configuration) -> BackgroundRealm {
          guard let fileURL = configuration.fileURL else {
              fatalError("Realm configurations without file URL not supported")
          }
      
          if let instance = instances[fileURL.absoluteString] {
              return instance
          } else {
              let queue = DispatchQueue(label: fileURL.lastPathComponent)
              var realm: Realm!
              queue.sync {
                  realm = try! Realm(configuration: configuration, queue: queue)
              }
              let instance = BackgroundRealm(realm: realm, queue: queue)
              instances[fileURL.absoluteString] = instance
              return instance
          }
      }
      
      private init(realm: Realm, queue: DispatchQueue) {
          self.realm = realm
          self.queue = queue
      }
      
      func execute(_ block: ((Realm) -> Void)) {
          queue.sync {
              autoreleasepool {
                  block(realm)
              }
          }
      }
      

      }

            Assignee:
            jason.flax@mongodb.com Jason Flax
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: