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 crash #8065

Closed
FreestyleRR opened this issue Dec 13, 2022 · 18 comments
Closed

App crash #8065

FreestyleRR opened this issue Dec 13, 2022 · 18 comments

Comments

@FreestyleRR
Copy link

FreestyleRR commented Dec 13, 2022

How frequently does the bug occur?

Sometimes

Description

When the application opens, a request is sent to the server, when it returns data, we delete the old ones from the database and immediately write new data, and I think at this moment several users crash.

Stacktrace & log output

First it delete object

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x7200 __pthread_kill + 8
1  libsystem_pthread.dylib        0x71ac pthread_kill + 268
2  libsystem_c.dylib              0x20c8c abort + 180
3  Realm                          0x2d5a9c please_report_this_issue_in_github_realm_realm_core_v_12_11_0 + 10
4  Realm                          0x2d5d84 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 260
5  Realm                          0x2d5be4 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 328
6  Realm                          0x1bd324 realm::StringIndex::do_delete(realm::ObjKey, realm::StringData, unsigned long) + 1936
7  Realm                          0x1bd4f4 realm::StringIndex::erase(realm::ObjKey) + 156
8  Realm                          0x284fc8 realm::Table::erase_from_search_indexes(realm::ObjKey) + 76
9  Realm                          0x18be6c realm::ClusterTree::erase(realm::ObjKey, realm::CascadeState&) + 44
10 Realm                          0x28ccf4 realm::Table::batch_erase_rows(realm::BPlusTree<realm::ObjKey> const&) + 1136
11 Realm                          0x2a6a10 realm::TableView::clear() + 144
12 Realm                          0x3ff034 realm::Results::clear() + 216
13 Realm                          0x130904 -[RLMResults deleteObjectsFromRealm] + 128
14 Realm                          0x128460 -[RLMRealm deleteObjects:] + 144
15 RealmSwift                     0xdc2b8 $s10RealmSwift0A0V6deleteyyAA7ResultsVyxGSo13RLMObjectBaseCRbzAA0A15CollectionValueRzlF + 92
16 MyApp                0x108214 closure #1 in closure #1 in CHIDatabaseController.deletePages() + 4346053140 (<compiler-generated>:4346053140)
17 MyApp                0x108328 partial apply for closure #1 in closure #1 in CHIDatabaseController.deletePages() + 4346053416 (<compiler-generated>:4346053416)
18 MyApp                0x22d58c thunk for @callee_guaranteed () -> (@error @owned Error) + 4347254156 (<compiler-generated>:4347254156)
19 MyApp                0x108340 partial apply for thunk for @callee_guaranteed () -> (@error @owned Error) + 4346053440 (<compiler-generated>:4346053440)
20 MyApp                0x22d5b4 thunk for @callee_guaranteed () -> (@unowned ()?, @error @owned Error) + 4347254196 (<compiler-generated>:4347254196)
21 MyApp                0x108358 partial apply for thunk for @callee_guaranteed () -> (@unowned ()?, @error @owned Error) + 4346053464 (<compiler-generated>:4346053464)
22 RealmSwift                     0xd9f40 $s10RealmSwift0A0V5write16withoutNotifying_xSaySo20RLMNotificationTokenCG_xyKXEtKlF + 392
23 MyApp                0x1080d8 closure #1 in CHIDatabaseController.deletePages() + 4346052824 (<compiler-generated>:4346052824)
24 MyApp                0xeee58 thunk for @escaping @callee_guaranteed () -> () + 4345949784 (<compiler-generated>:4345949784)
25 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release + 32
26 libdispatch.dylib              0x3fdc _dispatch_client_callout + 20
27 libdispatch.dylib              0x127f4 _dispatch_main_queue_drain + 928
28 libdispatch.dylib              0x12444 _dispatch_main_queue_callback_4CF + 44
29 CoreFoundation                 0x9a6f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
30 CoreFoundation                 0x7c058 __CFRunLoopRun + 2036
31 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
32 GraphicsServices               0x1368 GSEventRunModal + 164
33 UIKitCore                      0x3a23d0 -[UIApplication _run] + 888
34 UIKitCore                      0x3a2034 UIApplicationMain + 340
35 MyApp                0x4470 main + 25 (AppDelegate.swift:25)
36 ???                            0x1bc9f0960 (Missing)

Second it add object

Crashed: com.apple.main-thread
0  libsystem_platform.dylib       0xae8 _platform_memmove + 536
1  Realm                          0x15afb0 realm::Array::insert(unsigned long, long long) + 452
2  Realm                          0x1800e4 void realm::Cluster::do_insert_row<realm::ArrayString>(unsigned long, realm::ColKey, realm::Mixed, bool) + 152
3  Realm                          0x17f7d4 realm::util::FunctionRef<realm::IteratorControl (realm::ColKey)>::FunctionRef<realm::Cluster::insert_row(unsigned long, realm::ObjKey, realm::FieldValues const&)::$_1&>(realm::Cluster::insert_row(unsigned long, realm::ObjKey, realm::FieldValues const&)::$_1&)::'lambda'(void*, realm::ColKey)::__invoke(void*, realm::ColKey) + 456
4  Realm                          0x2a2174 realm::TableClusterTree::for_each_and_every_column(realm::util::FunctionRef<realm::IteratorControl (realm::ColKey)>) const + 84
5  Realm                          0x17af1c realm::Cluster::insert_row(unsigned long, realm::ObjKey, realm::FieldValues const&) + 208
6  Realm                          0x17ced8 realm::Cluster::insert(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&) + 240
7  Realm                          0x18cf38 realm::ClusterNodeInner::insert(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&)::$_1::operator()(realm::ClusterNode*, realm::ClusterNodeInner::ChildInfo&) const + 72
8  Realm                          0x188220 realm::ClusterNodeInner::insert(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&) + 232
9  Realm                          0x18ba04 realm::ClusterTree::insert_fast(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&) + 48
10 Realm                          0x18bc6c realm::ClusterTree::insert(realm::ObjKey, realm::FieldValues const&) + 48
11 Realm                          0x2a1cc0 realm::TableClusterTree::insert(realm::ObjKey, realm::FieldValues const&) + 52
12 Realm                          0x293638 realm::Table::create_object_with_primary_key(realm::Mixed const&, realm::FieldValues&&, realm::Table::UpdateMode, bool*) + 860
13 Realm                          0x17118 realm::Table::create_object_with_primary_key(realm::Mixed const&, bool*) + 80
14 Realm                          0xc5dc realm::Object realm::Object::create<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, std::__1::shared_ptr<realm::Realm> const&, realm::ObjectSchema const&, objc_object* __strong, realm::CreatePolicy, realm::ObjKey, realm::Obj*) + 624
15 Realm                          0xbfb0 RLMAccessorContext::createObject(objc_object*, realm::CreatePolicy, bool, realm::ObjKey) + 776
16 Realm                          0x5fd60 RLMAddObjectToRealm + 192
17 RealmSwift                     0xdaf78 $s10RealmSwift0A0V3add_6updateySo0aB6ObjectC_AC12UpdatePolicyOtF + 868
18 MyApp                0x34cf80 partial apply for closure #1 in closure #1 in CHIDatabaseController.add(record:) + 4345352064 (<compiler-generated>:4345352064)
19 RealmSwift                     0xd9f40 $s10RealmSwift0A0V5write16withoutNotifying_xSaySo20RLMNotificationTokenCG_xyKXEtKlF + 392
20 MyApp                0x34c604 closure #1 in CHIDatabaseController.add(record:) + 4345349636 (<compiler-generated>:4345349636)
21 MyApp                0xeee58 thunk for @escaping @callee_guaranteed () -> () + 4342869592 (<compiler-generated>:4342869592)
22 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release + 32
23 libdispatch.dylib              0x3fdc _dispatch_client_callout + 20
24 libdispatch.dylib              0x127f4 _dispatch_main_queue_drain + 928
25 libdispatch.dylib              0x12444 _dispatch_main_queue_callback_4CF + 44
26 CoreFoundation                 0x9a6f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
27 CoreFoundation                 0x7c058 __CFRunLoopRun + 2036
28 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
29 GraphicsServices               0x1368 GSEventRunModal + 164
30 UIKitCore                      0x3a23d0 -[UIApplication _run] + 888
31 UIKitCore                      0x3a2034 UIApplicationMain + 340
32 MyApp                0x4470 main + 25 (AppDelegate.swift:25)
33 ???                            0x1e060c960 (Missing)

Can you reproduce the bug?

Not yet

Reproduction Steps

I can't

Version

all(now using - 10.32.3)

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 16.0.2, 16.1.2 and other iOS versions

Build environment

Xcode version: ... 14.0

Dependency manager and version: ...

@dianaafanador3
Copy link
Contributor

Hi @FreestyleRR Can you please provide a sample project with a reproduction of the crashes.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Dec 13, 2022
@mr-grey
Copy link

mr-grey commented Dec 16, 2022

same crash in our project:

Crashed: serial-queue
0  libsystem_kernel.dylib         0x7200 __pthread_kill + 8
1  libsystem_pthread.dylib        0x71ac pthread_kill + 268
2  libsystem_c.dylib              0x20ca0 abort + 180
3  Realm                          0x2d58d4 please_report_this_issue_in_github_realm_realm_core_v_12_11_0 + 10
4  Realm                          0x2d5bbc realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 260
5  Realm                          0x2d5db8 realm::util::terminate_with_info(char const*, char const*, long, char const*, std::initializer_list<realm::util::Printable>&&) + 388
6  Realm                          0x156100 void realm::util::terminate_with_info<unsigned long&, unsigned long&, unsigned long const&, unsigned long&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(char const*, int, char const*, char const*, unsigned long&, unsigned long&, unsigned long const&, unsigned long&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) + 134
7  Realm                          0x155e94 realm::SlabAlloc::do_free(unsigned long, char*) + 1656
8  Realm                          0x1ad164 realm::WrappedAllocator::do_free(unsigned long, char*) + 24
9  Realm                          0x166408 realm::Array::destroy_deep(realm::MemRef, realm::Allocator&) + 64
10 Realm                          0x159ffc realm::Array::destroy_children(unsigned long) + 116
11 Realm                          0x16646c realm::Array::destroy_deep(realm::MemRef, realm::Allocator&) + 164
12 Realm                          0x159ffc realm::Array::destroy_children(unsigned long) + 116
13 Realm                          0x16646c realm::Array::destroy_deep(realm::MemRef, realm::Allocator&) + 164
14 Realm                          0x159ffc realm::Array::destroy_children(unsigned long) + 116
15 Realm                          0x16646c realm::Array::destroy_deep(realm::MemRef, realm::Allocator&) + 164
16 Realm                          0x159ffc realm::Array::destroy_children(unsigned long) + 116
17 Realm                          0x18b4f8 realm::ClusterTree::clear() + 56
18 Realm                          0x2a1cc0 realm::TableClusterTree::clear(realm::CascadeState&) + 160
19 Realm                          0x28cda0 realm::Table::clear() + 72
20 Realm                          0x3fee5c realm::Results::clear() + 200
21 Realm                          0x62170 RLMClearTable(RLMClassInfo&) + 208
22 Realm                          0x1306a0 -[RLMResults deleteObjectsFromRealm] + 100
23 Realm                          0x128210 -[RLMRealm deleteObjects:] + 144
24 Me                             0xddb7c partial apply for closure #1 in closure #1 in static RealmDuplicatedContact.deleteAll() + 430801599

func called to delete:

class RealmDuplicatedContact: Object {
  
    override static func primaryKey() -> String? {
        return "uuid"
    }
    
    @Persisted var apiPhoneNumber: APIPhoneNumber = APIPhoneNumber.random()
    
    @Persisted var phoneNumber = ""
    
    @Persisted var fullPhoneNumber = ""
    
    @Persisted var countryCode: String?
    
    @Persisted var name = ""
    
    @Persisted var initialCharacter = ""
    
    @Persisted var numberName = ""
    
    @Persisted var contactIdentifier = ""
    
    @Persisted var email: String?
    
    @Persisted var dateOfBirth: Date?
    
    @Persisted var imageKey: String?
    
    @Persisted var createdAt: Date?
    
    @Persisted var uuid: String = UUID().uuidString
}

static func deleteAll() {
       RealmManager.addOperation {
            guard let realm = RealmManager.sharedRealm else { return }
            let contacts = realm.objects(RealmDuplicatedContact.self)
            try? realm.safeWrite {
                realm.delete(contacts)
            }
        }
       
    }

@FreestyleRR
Copy link
Author

FreestyleRR commented Dec 20, 2022

Hi @FreestyleRR Can you please provide a sample project with a reproduction of the crashes.

I'm not sure but maybe I found why app crashed. When I deleting some data I called like that:

func deletePages() {
        try? realm().write {
            self.realm().delete(self.getPagesResult())
            self.realm().commitWrite()   <- Now I deleted this line...
        }
    }

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Dec 20, 2022
@mr-grey
Copy link

mr-grey commented Dec 22, 2022

Hi @FreestyleRR Can you please provide a sample project with a reproduction of the crashes.

I'm not sure but maybe I found why app crashed. When I deleting some data I called like that:

func deletePages() {
        try? realm().write {
            self.realm().delete(self.getPagesResult())
            self.realm().commitWrite()   <- Now I deleted this line...
        }
    }

using method Realm.write you don't need to commit , there already exist

@FreestyleRR
Copy link
Author

Hi @FreestyleRR Can you please provide a sample project with a reproduction of the crashes.

I'm not sure but maybe I found why app crashed. When I deleting some data I called like that:

func deletePages() {
        try? realm().write {
            self.realm().delete(self.getPagesResult())
            self.realm().commitWrite()   <- Now I deleted this line...
        }
    }

using method Realm.write you don't need to commit , there already exist

I managed to reproduce one of the crashes.
This happens when i enter the application and the data is reloaded and when it arrives it is overwritten in the database. And I immediately tried to go to the screen that uses the data from the database, but they have already been deleted and the new ones apparently did not have time to overwrite, and the link to the object remained old. How to be in such a situation, I have more than one such crash on the project.
this happens when i enter the application and the data is reloaded and when it arrives it is overwritten in the database. And I immediately tried to go to the screen that uses the data from the database, but they have already been deleted and the new ones apparently did not have time to overwrite, and the link to the object remained old. How to be in such a situation, I have more than one such crash on the project.

Screenshot 2022-12-22 at 09 40 04

Screenshot 2022-12-22 at 09 38 59

@FreestyleRR
Copy link
Author

When the data comes in, I delete it like this and immediately overwrite it.
Сan you tell me how to do it right or better?
Screenshot 2022-12-22 at 09 50 03
Screenshot 2022-12-22 at 09 50 13

@FreestyleRR
Copy link
Author

One more...

Screenshot 2022-12-22 at 14 59 27

@dianaafanador3
Copy link
Contributor

@FreestyleRR your last screenshot seems unrelated to the others stack traces. Are you using any library which does some method/class runtime manipulation, like FirebaseSwizzlingUtilities or FirebasePerformance SDKs which may be causing this issue. If you are able to reproduce this, please can your create a repo with a a sample project so we can work on this.

Regarding the other two screenshots.
I would recommend to not delete or add using not updated references to the objects
For example;

func deletePages(){
   let realm = try? Realm() // with your configuration
   try? realm .write {
      let objectsToDelete = realm.objects(MyObject.self) // query the objects to delete
      realm.delete(objectsToDelete)
   }
}   

And instead of doing a write for every object, try to do this in a batch, this will make the write faster and the commit for all objects will happen at the same time.

If you use a reference in a View to an object which is gonna be deleted, when you do read it, it will throw because the object has been invalidated.
Try to use a query (which are live and will change depending of the data in the realm) as a datasource instead of an object which you don't know if it will be deleted.

Lastly check if the object is invalidated before rendering it on the view, if you want to use an object as a reference and you don't know if it will get invalidated.

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Jan 4, 2023
@ydeveloperios
Copy link

Have similar crash report, but can't reproduce.
Is this partplease_report_this_issue_in_github_realm_realm_core_v_12_11_0 important? If I update version of Realm, maybe, it can help?

@papfonseca
Copy link

papfonseca commented Mar 17, 2023

Hi! Same is happening to us. Any news on that?
Here is the stack trace

0    libsystem_kernel.dylib                   0x2027002f4     __pthread_kill + 8
1    libsystem_c.dylib                        0x1d0de5e9c     abort + 123
2    Realm                                    0x10505dfe4     please_report_this_issue_in_github_realm_realm_core_v_12_11_0 + 11
3    Realm                                    0x10505e2cc     realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 259
4    Realm                                    0x10505e12c     realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 327
5    Realm                                    0x104f4586c     realm::StringIndex::do_delete(realm::ObjKey, realm::StringData, unsigned long) + 1935
6    Realm                                    0x104f45a3c     realm::StringIndex::erase(realm::ObjKey) + 155
7    Realm                                    0x10500d510     realm::Table::erase_from_search_indexes(realm::ObjKey) + 75
8    Realm                                    0x104f143b4     realm::ClusterTree::erase(realm::ObjKey, realm::CascadeState&) + 43
9    Realm                                    0x10500f104     realm::Table::remove_object(realm::ObjKey) + 263
10   Realm                                    0x104f81f9c     realm::Obj::remove() + 43
11   Realm                                    0x104de89e4     RLMDeleteObjectFromRealm (RLMObjectStore.mm:180)
12   RealmSwift                               0x1058317d4     Realm.delete<A>(_:) (Realm.swift:700)

EDIT:

This happens when we try to delete some objects:

    func deleteDashboardEvents(for uuid: String) {
        let realm = try! Realm()
        let events = DashboardEvent.fetchLiveEvents(realm: realm, for: uuid)
        
        guard events.count > 0 else { return }
        
        do {
            try realm.write {
                realm.delete(events)
            }
        } catch {
            FTLog(.realm, .error, "Could not delete live events cards")
        }
    }

We're using the latest version, Realm (10.37.0).

@dianaafanador3
Copy link
Contributor

Hi @papfonseca can you please attach how are you getting the events to delete, specifically the implementation of DashboardEvent.fetchLiveEvents(realm:,for:). If you are able to reproduce this issue, it will be very helpful if you can share a repro project, so it is easier for us to diagnose this.

@dianaafanador3
Copy link
Contributor

@FreestyleRR did you try the suggestions from my comment above?. Any updates on this issues after updating to our latest version?

@FreestyleRR
Copy link
Author

@FreestyleRR did you try the suggestions from my comment above?. Any updates on this issues after updating to our latest version?

@dianaafanador3 the last answer from this thread helped me - #8177

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Apr 12, 2023
@dianaafanador3
Copy link
Contributor

Closing this as this seems to be related to the use of another library

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label Apr 12, 2023
@papfonseca
Copy link

papfonseca commented Apr 21, 2023

Hi @dianaafanador3

Here it is:

    static func fetchLiveEvents(realm: Realm = try! Realm(), uuid: String) -> [DashboardEvent] {
        return realm.objects(DashboardEvent.self)
            .filter("uuid = %@ AND category = %@", uuid, EventCategory.liveEvent.rawValue)
            .sorted(byKeyPath: "timestamp", ascending: false)
            .toArray()
    }

Unfortunately We couldn't reproduce it. When this happens, the app is always crashing.
In production, to 'fix' this problem, we created a new app version, incremented the schemaVersion and on the migrationBlock we deleted the DashboardEvent content:

                if oldSchemaVersion < 36 {
                    // there is a crash in DashboardEvent and Andreia couldnt open the app
                    // the crash happens when the app tries to delete live events
                    // it could be something corrupted in DashboardEvent table
                    let result = migration.deleteData(forType: DashboardEvent.className())
                    FTLog(.realm, .info, "Did delete dashboard events: \(result)")
                }

It looks like something get corrupted in the DashboardEvent.
Hope it helps.


EDIT: I'll try the FreestyleRR suggestion.

@1512067539
Copy link

你好,请问我遇到同样的问题,App启动的时候崩溃了。
Uploading WX20231207-101307.png…

@1512067539
Copy link

image
我遇到了这个问题,请问是什么原因?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants