Realm-cocoa: Production app crashing on iOS 13

Created on 27 Sep 2019  路  12Comments  路  Source: realm/realm-cocoa

We are using realm database in our app from many years, But suddenly all our apps are crashing when we run them on iOS 13. It only happens in production build and i can assure there are no changes in the response or anything we have debugged to the core. The app is running good in iOS 12 and I'm it's a issue of iOS 13.

From our research I think this is the related issue : https://github.com/realm/realm-cocoa/issues/6163#issuecomment-498620496 because the crash is occuring in the models where we are using defaultPropertyValues with random string.

Goals

Want to fix crash in production app

Expected Results

Successfully add field in database

Actual Results

0 libobjc.A.dylib 0x00000001c29b9030 objc_retain + 16 (objc-object.h:459)
1 App 0x0000000100bf6eec +[Task addUpdateObject:] + 668 (Task:43)
2 App 0x0000000100ba38c4 +[RLMManager writeGetAll:completion:] + 5120 (RLMManager.m:292)
3 App 0x0000000100b7d1fc __33+[ServerManager callGetAllAPI:]_block_invoke + 484 (ServerManager.m:1566)
4 App 0x0000000100c021a8 __64+[Networking callAPI:WithHeader:WithParams:completionHandler:]_block_invoke_3 + 616 (Networking.m:0)
5 CFNetwork 0x00000001c5e8d2cc __40-[__NSURLSessionLocal taskForClassInfo:]_block_invoke + 32 (LocalSession.mm:713)
6 CFNetwork 0x00000001c5e9d800 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 216 (LocalSessionTask.mm:566)
7 Foundation 0x00000001c303b61c __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16 (NSOperation.m:1541)
8 Foundation 0x00000001c2f453d8 -[NSBlockOperation main] + 100 (NSOperation.m:1560)
9 Foundation 0x00000001c303d8a4 __NSOPERATION_IS_INVOKING_MAIN__ + 20 (NSOperation.m:2184)
10 Foundation 0x00000001c2f45070 -[NSOperation start] + 732 (NSOperation.m:2201)
11 Foundation 0x00000001c303e29c __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 20 (NSOperation.m:2215)
12 Foundation 0x00000001c303dd68 __NSOQSchedule_f + 180 (NSOperation.m:2226)
13 libdispatch.dylib 0x00000001c28f681c _dispatch_block_async_invoke2 + 104 (queue.c:522)
14 libdispatch.dylib 0x00000001c2944184 _dispatch_client_callout + 16 (object.m:495)
15 libdispatch.dylib 0x00000001c28eca9c _dispatch_continuation_pop$VARIANT$mp + 412 (inline_internal.h:2487)
16 libdispatch.dylib 0x00000001c28ec1f0 _dispatch_async_redirect_invoke + 600 (queue.c:800)
17 libdispatch.dylib 0x00000001c28f8fd0 _dispatch_root_queue_drain + 376 (inline_internal.h:2528)
18 libdispatch.dylib 0x00000001c28f979c _dispatch_worker_thread2 + 128 (queue.c:6569)
19 libsystem_pthread.dylib 0x00000001c2993f64 _pthread_wqthread + 212 (pthread.c:2336)
20 libsystem_pthread.dylib 0x00000001c2996ae0 start_wqthread + 8

Steps to Reproduce

Crash every time when running into iOS 13

Version of Realm and Tooling

Realm framework version: 3.18
Xcode version: 11.1
iOS/OSX version: 13.1
Language : Objective-C

Please help us out as soon as possible, all of our client are stuck. It's a big database app having thousands of records, any kind of help will be truly appreciated.

O-Community T-Help

All 12 comments

"Crash every time when running into iOS 13" are not steps I can take to reproduce the problem. If you can share an app that runs into problems (either your real app or a sample one that hits the same crash) I can look into that, but there isn't much I can do to help with just a stack trace.

this app crashes for the release build only, is there any chance if there is some differences in the configuration of the build for the realm?
Like app works fine in debug mode and enterprise release, but when we create an app store build it crashes,
for more details, it crashes in the function addorupdateobject

@tgoyne I know it's hard to convey but if I had the exact issue I would've provided here. It is only crashing for the appstore build not for development or enterprise build and that's why we are not able to debug the issue correctly, so far from our research we think that defaultPropertyValues is getting ignored for the class where the primary key is random string because before the crash we also add some field in the database but they have there primary added manually.

I found the issue and will post it here soon. Thanks for the help.

Hey - looks like you forgot to add a T-* label - could you please add one (if you have access to add labels)?

Hey @tryWabbit can you post what the issue is ? thanks.

@tryWabbit can you post it? I had similar issue on getting the result count function. (Production app)
When I get the count of results this part is crashed the app with that part.
dynamicBridgeCast(fromObjectiveC: rlmResults.object(at: UInt(position)))

My app working with swift3 version and use RealmSwift 3.0.2.

@krymtn @hovox
Sorry about replying late, I was away from development for some reason.
In my case the issue was totally different and unpredictable. It was happening with the following condition
1) Was crashing only on iOS 13.
2) Was crashing only in production app, we tried in develop and distribution certificate builds but it was only crashing on iOS 13 with production build.

Now coming to the issue

We had an old C function in our app that was used to generate random string like this :-

NSString *getUniqueString(void){
     NSString *uuidStr = [NSUUID UUID].UUIDString;
     uuidStr = [uuidStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
     return uuidStr;
 }

In our app Many objects were having a random primary key that was by that method and it may seem strange when the object was created with this method in iOS 13, the primary key of the object was containing itself an object.

That was causing the error at my end, we removed that method and it was working fine. I still don't know what was the reason but it was occurring with the combination of ios13 + production build + that method.

Thanks for your replay.
Our issue is different but still exists only in iOS 13:
https://gist.github.com/0xced/56035d2f57254cf518b5
The example in the link works fine in iOS 12 by returning error, in iOS 13 it crashes with objc_retain + 16. The solution is not pass error parameter and check if data is nil.

@tryWabbit thx for your response.

I fixed also my problem. My projects were running on Swift3 and Xcode 10.1 (and my realm version was 3.0.2) I migrated the project swift3 to swift 4.2 and using 3.18.0(Realm version). The problem is gone.

I also got this problem on one of my time-sensitive app. I have a Realm Object class called Settings. Which has 2 fields key and value and both are Strings. key is the primary key (key can be any random sstring) and I have written an extension to get the value when key provided. That's where the problem occurs. It only occurs in production and test flight versions. never on debug version.
let version = Setting.int(.currentVersion)
this is inside AppDelegate appLaunchWIth options method. And app crashes without coming to launch screen, only in the production build. I tried many things and it always failed on my iPhoneXS with iOS 13.2. But iPhone 7 with iOS 13.2 is OK. And I got reports from clients with X and XS phones too. Luckily my app is relatively small and I was able to convert it to CoreData whithing a reasonable time and release it. Now it's OK. But please look into it. Another one of my app bete versions giving the error now. I wanna release it but I cannot ith this error. It only occurs if you build it with the lastest Xcode. Older apps are working fine on those problematic devices.

We also experienced a new build crashing in release and not in debug - in some devices. We couldn't find the exact reason why but we were using realm through SPM, it got solved when we removed it from SPM and used Carthage again. I hope it helps somebody.

Was this page helpful?
0 / 5 - 0 ratings