realm / realm-swift

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

Realm crash(EXC_BAD_ACCESS KERN_PROTECTION_FAILURE) upon force closing app #2913

Closed rscholtes closed 9 years ago

rscholtes commented 9 years ago

Hello,

We just launched a test version of our app in the appstore and are receiving lots of crashreports through crashlytics. We managed to reproduce this crash through force killing the app. The actual networking task is already done, so there should be no reason for this crash to occure.

The app crashes with the following stacktrace:

Thread : Crashed: com.apple.main-thread
0  Realm                          0x10120622c realm::_impl::WriteLogCollector::do_prepare_commit(realm::SharedGroup&, unsigned long long) + 372
1  Realm                          0x10117edf8 realm::SharedGroup::do_commit() + 80
2  Realm                          0x1010cbc64 realm::SharedGroup::commit_and_continue_as_read() + 60
3  Realm                          0x1010c93cc -[RLMRealm commitWriteTransaction:] + 100
4  Realm                          0x1010c9570 -[RLMRealm transactionWithBlock:error:] + 100
5  RealmSwift                     0x1013bac84 _TFC10RealmSwift5Realm5writefS0_FzFT_T_T_ + 140
-----
8  AFNetworking                   0x100d57dc8 __84-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:success:failure:]_block_invoke74 + 116
9  AFNetworking                   0x100d6b8f4 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_271 + 144
10 libdispatch.dylib              0x1977e56e8 _dispatch_call_block_and_release + 24
11 libdispatch.dylib              0x1977e56a8 _dispatch_client_callout + 16
12 libdispatch.dylib              0x1977eadb0 _dispatch_main_queue_callback_4CF + 1844
13 CoreFoundation                 0x1824bc1f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
14 CoreFoundation                 0x1824ba060 __CFRunLoopRun + 1628
15 CoreFoundation                 0x1823e8ca0 CFRunLoopRunSpecific + 384
16 GraphicsServices               0x18d624088 GSEventRunModal + 180
17 UIKit                          0x187b00ffc UIApplicationMain + 204
18 OSM                            0x1001839cc main (AppDelegate.swift:15)
19 libdyld.dylib                  0x1978168b8 start + 4
bmunkholm commented 9 years ago

Doesn't Crashlytics provide any more details about the crash from the users? As much detail as possible is really useful.

galip91 commented 9 years ago

No, but we did log the application lifecycle ourselves and found out the crash happens when applicationWillTerminate gets called.

0   |   09:48:41:060    |   applicationDidBecomeActive
1   |   09:48:44:664    |   applicationWillResignActive
2   |   09:48:45:590    |   applicationDidEnterBackground
3   |   09:48:45:605    |   applicationWillTerminate
bmunkholm commented 9 years ago

Where do you see the crash reason listed in the subject of this issue?

rscholtes commented 9 years ago

Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x0000000102bdc000

followed by stacktrace

rscholtes commented 9 years ago

i've set up a project reproducing this error if that helps any

mrackwitz commented 9 years ago

Yes, please that would help quite a lot! You can send it privately to help@realm.io.

liuxuan30 commented 9 years ago

is it reproducible all the time in applicationWillTerminate?

rscholtes commented 9 years ago

yes it is, i send you guys the project to reproduce this

liuxuan30 commented 9 years ago

@rscholtes I am considering importing Realm recently, but it seems this is quite a serious bug?

mrackwitz commented 9 years ago

@rscholtes: Thanks, we received your project and are looking into it. I'll keep you up to date here with the results of our investigations.

jpsim commented 9 years ago

We believe this issue to be fixed in our master branch, which should be made available in an official release shortly. I'd appreciate if you could try integrating that version into your apps to see if the issue occurs again. Thanks for your patience!

liuxuan30 commented 8 years ago

@jpsim do you mind share what's the root cause? The PR just add a few methods

jpsim commented 8 years ago

@jpsim do you mind share what's the root cause? The PR just add a few methods

That's because the fix happened externally, in our core database engine, which is a binary dependency of realm-cocoa.

The issue is a bit complex, but it boils down to incorrectly handling a race between a commit and a new thread or process opening the database, which could result in a crash.

liuxuan30 commented 8 years ago

Thanks!

rscholtes commented 8 years ago

We released a new version of our app, and this crash has been resolved!