Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashed while writing value in Realm db , EXC_CRASH (SIGKILL) #7387

Open
ZeeshanMavenir opened this issue Aug 10, 2021 · 11 comments
Open

Comments

@ZeeshanMavenir
Copy link

ZeeshanMavenir commented Aug 10, 2021

Relam version '10.7.6'

Incident Identifier: 18xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
Beta Identifier: 39xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
Hardware Model: iPhone10,4
Process: AppName [355]
Path: /private/var/containers/Bundle/Application/232779E2-0DCB-45CF-A939-4AA54EFFCB9A/AppName.app/AppName
Identifier: com.tmobile.phone2
Version: 4.x.1xx (4.x.1xx)
AppStoreTools: 12E506
AppVariant: 1:iPhone10,4:14
Beta: YES
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.tmobile.phone2 [426]

Date/Time: 2021-08-10 07:29:50.1185 -0700
Launch Time: 2021-08-09 12:27:46.9800 -0700
OS Version: iPhone OS 14.7.1 (18G82)
Release Type: User
Baseband Version: 4.0x.xx
Report Version: 10xx

Exception Type: EXC_CRASH (SIGKILL)

3 Realm 0x0000000102c912e4 realm::DB::do_begin_write+ 1233636 () + 68
4 Realm 0x0000000102ed4c34 realm::_impl::transaction::begin+ 3607604 (std::__1::shared_ptr<realm::Transaction> const&, realm::BindingContext*, realm::_impl::NotifierPackage&) + 356
5 Realm 0x0000000102ec9df0 realm::_impl::RealmCoordinator::promote_to_write+ 3562992 (realm::Realm&) + 268
6 Realm 0x0000000102f409d4 realm::Realm::begin_transaction+ 4049364 () + 148
7 Realm 0x0000000102c33300 -[RLMRealm beginWriteTransactionWithError:]
+ 848640 (RLMRealm.mm:0)
8 RealmSwift 0x00000001034efee0 Realm.write<A>(withoutNotifying:_:)
+ 245472 (<compiler-generated>:0)
9 App Name 0x000000010124a850 specialized closure #1 in UnifiedClass.save+ 17901648 (item:)
+ 212
10 App Name 0x0000000100466b30 thunk for @callee_guaranteed () -> (@error @owned Error) + 3337008 (<compiler-generated>:0)
11 App Name 0x0000000100629c44 partial apply for thunk for @callee_guaranteed () -> (@error @owned Error) + 5184580 (<compiler-generated>:0)
12 App Name 0x0000000100629e7c thunk for @callee_guaranteed () -> + 5185148 (@error @owned Error)partial apply + 12
13 libswiftObjectiveC.dylib 0x00000001caf14f50 0x1caf13000 + 8016
14 App Name 0x00000001006250a8 AppClass.saveAppData(devicePushToken:)
+ 5165224 (<compiler-generated>:0)
15 App Name 0x0000000101368a04 specialized AppClass.saveAppData(_:didUpdate:for:)
+ 19073540 (PNManager.swift:104)
16 App Name 0x00000001013666c0 @objc AppClass.saveAppData(_:didUpdate:for:)
+ 19064512 (<compiler-generated>:0)
@pavel-ship-it
Copy link
Contributor

@ZeeshanMavenir thank you for submitting the issue.

Can you give us more information on how you saving the data?
Maybe you can share a code sample and steps to reproduce?

@ZeeshanMavenir
Copy link
Author

ZeeshanMavenir commented Aug 16, 2021

@pavel-ship-it ,
Steps to reproduce
It is occurring immediately after app launch, during app launch we have a db write activity after receiving push token.

Sample Pseudo code

Class PushManager{

func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    var token =     credentials.token.base64EncodedString(options: .lineLength64Characters);
    if(!token.isEmpty) {
        //Defaults[\.pushtoken] = token
        DataObject.shared.setDevicePushToken(devicePushToken:token)
    }
}

}

Class DataObject{

func updateTokenInDb(){
    let realmInstance = getRealmInstance()
    Let  entity = realmInstance.objects(Entity.self).filter(predicate)
    entity.Token = newToken
    updateRealmObject(entity)
}

func updateRealmObject(entity : RealmEntity)
let realmInstance = getRealmInstance()
if realmInstance.isInWriteTransaction {
    realmInstance.add(entity, update: .all)
} else {
    try realmInstance.write {
        realmInstance.add(entity, update: .all)
    }
}

}

@pavel-ship-it
Copy link
Contributor

What do you mean by 'write actively' ? Is it long lasting process or is it involve a number of simultaneous transactions or is it something else?

The code for updateTokenInDb() and updateRealmObject(entity : RealmEntity) looks risky.

  • You're getting the Realm instance in every method. Can you guarantee it will be the same instance?
  • Why do you have the additional checking for isInWriteTransaction? Trying to manually manage the transactions can lead to very unpleasant consequences.

You can refer Realm documentation on Threading https://docs.mongodb.com/realm/sdk/ios/advanced-guides/threading/ to get an advice on both issues.

As a quick workaround you could update updateTokenInDb to write the entity in the same method using the same Realm instance.

@ZeeshanMavenir
Copy link
Author

@pavel-ship-it , I was talking about db write activity and not ‘writing actively’ as u have interpreted, it is not a long running process, just a single property update.

We are creating a fresh realm instance for every read/write transaction.


isInWriteTransaction check is added to avoid multiple write transactions, we had earlier faced crashes because of multiple write transactions causing realm memory crashes.

@ZeeshanMavenir
Copy link
Author

Hey @pavel-ship-it Do u need any further info from our side in analysing the issue?, if yes please let me know the details u are looking for.

@jsflax
Copy link
Contributor

jsflax commented Oct 29, 2021

@JituDeore msync failing sounds like it could be a permissions issue. Is this a readonly file?

@JituDeore
Copy link

@jsflax No its not.

@jsflax
Copy link
Contributor

jsflax commented Oct 29, 2021

Does your app have access to the file? Is this changed behaviour?

@JituDeore
Copy link

JituDeore commented Oct 29, 2021

Yes we have the access. We are accessing the file other places and its working as expected only seeing this crash on iOS 15 users. Same code is working as it is for older OS.

@jsflax
Copy link
Contributor

jsflax commented Oct 29, 2021

Do you have data protection entitlement added to your app? Can you give us more info as to the general settings and capabilities of your application?

@JituDeore
Copy link

Do you have data protection entitlement added to your app

:- No we don't have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants