realm / realm-swift

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

Realm crashes on addOrUpdateObject, but only in some environments #1663

Closed eliasbagley closed 9 years ago

eliasbagley commented 9 years ago

Hey - I'm getting the following crash on Realm 0.91.1 Swift:

array.cpp:453: [realm-core-0.88.1] Assertion failed: ndx < m_size
0 Realm 0x000000010da6f566 ZN7tightdb4util9terminateEPKcS2_l + 454
1 Realm 0x000000010da76f3f _ZN7tightdb5Array3setEmx + 399
2 Realm 0x000000010db05ad8 _ZN7tightdb6Column3setEmx + 296
3 Realm 0x000000010db09986 _ZN7tightdb14ColumnBackLink12add_backlinkEmm + 358
4 Realm 0x000000010db8e238 _ZN7tightdb5Table11do_set_linkEmmm + 216
5 Realm 0x000000010db8dec4 _ZN7tightdb5Table8set_linkEmmm + 388
6 Realm 0x000000010da2bd59 _ZL11RLMSetValueP13RLMObjectBasemS0_m + 518
7 Realm 0x000000010da2886c RLMDynamicSet + 1518
8 Realm 0x000000010da3c193 RLMAddObjectToRealm + 1674
9 Realm 0x000000010da5a72b -[RLMRealm addOrUpdateObject:] + 123
10 gobeios 0x00000001096a63ef _TFFC7gobeios16TeamQueueManagerP33_BBE8B5E29DC6908739F3885AAC76B01624queuedChallengesFromJSONFS0_FGVSs10DictionarySSPSs9AnyObject__GSaC6Models15QueuedChallenge_U_FGS1_SSPS2___S4 + 607
11 gobeios 0x00000001096a656e TTRXFo_oGVSs10DictionarySSPSs9AnyObject___oC6Models15QueuedChallenge_XFo_iGS_SSPS0____iS2_ + 30
12 gobeios 0x00000001096a43a1 TPA__TTRXFo_oGVSs10DictionarySSPSs9AnyObject___oC6Models15QueuedChallenge_XFo_iGS_SSPS0____iS2_ + 81
13 libswiftCore.dylib 0x000000010ee942fc TFVSs17MapCollectionViewg9subscriptFQQ_5IndexQ0 + 172
14 libswiftCore.dylib 0x000000010ee94ce0 TTWUSs14CollectionType__USs13GeneratorType__Ss16ForwardIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible____GVSs17MapCollectionViewQ_Q0__S_SsFS_g9subscriptFQQPS_5IndexQQS5_9Generator7Element + 112
15 libswiftCore.dylib 0x000000010ee90f56 _TFVSs26LazyRandomAccessCollectiong9subscriptFQQ_5IndexQQQ_9Generator7Element + 86
16 libswiftCore.dylib 0x000000010ee91145 _TTWUSs14CollectionType_USs13GeneratorType__Ss21RandomAccessIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible_Ss16SignedNumberType_S3_____GVSs26LazyRandomAccessCollectionQ__Ss15_CollectionTypeSsFS6_g9subscriptFQQPS6_5IndexQS7_8_Element + 85
17 libswiftCore.dylib 0x000000010ee369df _TFSs34_copyCollectionToNativeArrayBufferUSs15_CollectionTypeSs14_Sequence_Type_USs13GeneratorType__Ss16ForwardIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible___FQ_GVSs22_ContiguousArrayBufferQQ_8_Element + 943
18 libswiftCore.dylib 0x000000010ee914f5 TTWUSs14CollectionType_USs13GeneratorType__Ss21RandomAccessIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible_Ss16SignedNumberType_S3_____GVSs26LazyRandomAccessCollectionQ__Ss12SequenceTypeSsZFS6_oi2tgUS6__US0____fMQPS6_FTS7_TVSs24_CopyToNativeArrayBufferT___GVSs22_ContiguousArrayBufferQQS7_9Generator7Element + 341
19 libswiftCore.dylib 0x000000010ee2b8ee TFSa3mapU__fGSaQ__U__FFQd__Q_GSaQ_ + 830
20 gobeios 0x00000001096a3545 TFC7gobeios16TeamQueueManagerP33_BBE8B5E29DC6908739F3885AAC76B01624queuedChallengesFromJSONfS0_FGVSs10DictionarySSPSs9AnyObject__GSaC6Models15QueuedChallenge + 565
21 gobeios 0x00000001096a4ca6 TFFC7gobeios16TeamQueueManager22getQueuedChallengeListFS0_FTSi6paramsGSqGVSs10DictionarySSPSs9AnyObject___10completionFT8responseOS_27QueuedChallengeListResponse_T__C9Alamofire7RequestU_FTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqPS2___GSqCSo7NSError__T + 998
22 gobeios 0x00000001096a286b TPA__TFFC7gobeios16TeamQueueManager22getQueuedChallengeListFS0_FTSi6paramsGSqGVSs10DictionarySSPSs9AnyObject___10completionFT8responseOS_27QueuedChallengeListResponse_T__C9Alamofire7RequestU_FTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqPS2___GSqCSo7NSError__T + 123
23 Alamofire 0x000000010debfec0 TFFFC9Alamofire7Request8responseFDS0_FT5queueGSqCSo8NSObject_10serializerFTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqCSo6NSData__TGSqPSs9AnyObject__GSqCSo7NSError__17completionHandlerFTS2_GSqS3__GSqPS5___GSqS6___T__DS0_U_FT_T_U_FT_T + 496
24 libdispatch.dylib 0x000000010f2fb186 dispatch_call_block_and_release + 12
25 libdispatch.dylib 0x000000010f31a614 dispatch_client_callout + 8
26 libdispatch.dylib 0x000000010f302a1c _dispatch_main_queue_callback_4CF + 1664
27 CoreFoundation 0x000000010e701229 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
28 CoreFoundation 0x000000010e6c2dfb __CFRunLoopRun + 2043
29 CoreFoundation 0x000000010e6c2396 CFRunLoopRunSpecific + 470
30 GraphicsServices 0x00000001100b6a3e GSEventRunModal + 161
31 UIKit 0x000000010c1f1f10 UIApplicationMain + 1282
32 gobeios 0x00000001097c91f7 main + 135
33 libdyld.dylib 0x000000010f34f145 start + 1
IMPORTANT: if you see this error, please send this log to help@realm.io.

The strange part about this crash is that it only happens in my environment - it won't happen if I run the exact same code on a coworkers machine. The crash doesn't happen when I remove some properties from the model, but I don't think those properties I removed are the root cause, just somehow manifesting the bug.

My question is - what is a likely culprit for this to track it down, or is there a way I can get a more helpful error other than "ndx < m_size" ? I've tried updating the OS, Xcode, command line tools, Realm versions yet the problem persists so I'm not sure what in my environment could actually be affecting this. Thanks!

yoshyosh commented 9 years ago

Hi @eliasbagley thanks for sending this in. This was fixed in the latest versions of Realm, can you try downloading them and letting us know if you're still running into any issues? I believe you're using an older version based on this line array.cpp:453: [realm-core-0.88.1] Assertion failed: ndx < m_size core is now at 0.88.5.

This is something that has to be debugged at the core level, usually we request you send a sample project that we can use to look into it further. Can you give the latest version a shot first?

eliasbagley commented 9 years ago

How do I make sure I'm using the latest core version? I'm using Carthage for dependency management, and the .xcproj file it downloads shows that it's using Realm 0.91.1, but I only see folders for core-0.88.0 and core-0.88.1. How do I get it to use 0.88.5?

yoshyosh commented 9 years ago

The only way I can guarantee that right now is if you downloaded the framework directly from realm.io. I did open up an issue so that Carthage can get updated. Can you let me know how this works out and if it solves your error?

yoshyosh commented 9 years ago

@eliasbagley jp tried using 0.91.1 and things went smoothly using the latest version of core. You can read more here https://github.com/realm/realm-cocoa/issues/1664. It could be an issue with carthage, keep me posted based on what you do with this new info

jpsim commented 9 years ago

@eliasbagley please provide us with a reproducible case of this issue and we'll be happy to reopen and investigate.