realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.23k stars 2.14k forks source link

Realm v0.92.3 Bug: RLMException in RLMCheckThread Function #1947

Closed ghost closed 9 years ago

ghost commented 9 years ago

I just updated from Realm v0.92.2 to v0.92.3 and now our app keeps crashing if we execute the following code in our sync logic:

import Async

Async.background {
  let realm = Realm()
  realm.write {
    realm.delete(realm.objects(MyObject))
    realm.add(self.myObjects)
  }
}

Reason: Realm accessed from incorrect thread

I always instantiate and access the Realm object in the same thread (no shared realm between threads). Don't know what you changed vom v0.92.2 to v0.92.3 but that wasn't a good idea ^^

Stack Trace:

0  myapp                          0x000f8ecb CLSProcessRecordAllThreads + 114
1  myapp                          0x000f90d9 CLSProcessRecordAllThreads + 640
2  myapp                          0x000e8aaf CLSHandler + 30
3  myapp                          0x000f80c7 __CLSExceptionRecord_block_invoke + 1150
4  libdispatch.dylib              0x32e432cf _dispatch_client_callout + 22
5  libdispatch.dylib              0x32e4aa3d _dispatch_barrier_sync_f_invoke + 48
6  myapp                          0x000f7bf7 CLSExceptionRecord + 234
7  myapp                          0x000f7a41 CLSExceptionRecordNSException + 576
8  myapp                          0x000f7675 CLSTerminateHandler() + 152
9  libc++abi.dylib                0x3220dde3 std::__terminate(void (*)()) + 78
10 libc++abi.dylib                0x3220d5a9 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*) + 110
11 libobjc.A.dylib                0x328d8d5f objc_exception_throw + 250
12 Realm                          0x0049f427 RLMCheckThread(RLMRealm*) + 74
13 Realm                          0x0049f315 -[RLMObjectBase dealloc] + 200
14 libobjc.A.dylib                0x328f2d5f objc_object::sidetable_release(bool) + 166
15 myapp                          0x000962d8 _TPA__TFFC9myapp14SyncStudyStateP33_0D896500AA739B04C2B11E484EEBA05A19parseStudyPlanLinksFS0_FTSSGSqCSo17NSHTTPURLResponse_CS_10StudyState_T_U_FT_T_ + 164
16 Alamofire                      0x003c4ec8 _TFC9Alamofire7Request14responseStringfDS0_FT8encodingGSqSu_17completionHandlerFTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqSS_GSqCSo7NSError__T__DS0_ + 336
17 Alamofire                      0x003b7524 _TPA__TTRXFo_dVSs5Int64dS_dS__dT__XFo_iTS_S_S___iT__ + 204
18 Alamofire                      0x003b7650 block_destroy_helper + 16
19 libsystem_blocks.dylib         0x32e7fae1 _Block_release + 216
20 Foundation                     0x252bb93d -[NSBlockOperation dealloc] + 60
21 libobjc.A.dylib                0x328f2d5f objc_object::sidetable_release(bool) + 166
22 libobjc.A.dylib                0x328f31a9 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 404
23 libdispatch.dylib              0x32e4d4d1 _dispatch_root_queue_drain + 1724
24 libdispatch.dylib              0x32e4e3c3 _dispatch_worker_thread3 + 94
25 libsystem_pthread.dylib        0x32faadc1 _pthread_wqthread + 668
26 libsystem_pthread.dylib        0x32faab14 start_wqthread + 8
segiddins commented 9 years ago

@christianlanz I'm guessing that self here has some reference to an Object that was obtained on another thread. This is a duplicate of https://github.com/realm/realm-cocoa/issues/1893, and we intend to make it safe to deallocate an Object on any thread in an upcoming release of Realm.