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

Slab allocator crashes deleting a block #6922

Closed
alanipce opened this issue Aug 24, 2023 · 5 comments · Fixed by #6962
Closed

Slab allocator crashes deleting a block #6922

alanipce opened this issue Aug 24, 2023 · 5 comments · Fixed by #6962

Comments

@alanipce
Copy link

alanipce commented Aug 24, 2023

SDK and version

SDK : Swift
Version: 10.42.0

Observations

  • How frequent do the crash occur? ~200-300 users / day with app autoupdate rolled out to 2% of users
  • Does it happen in production or during dev/test? production
  • Can the crash be reproduced by you? no
  • Can you provide instructions for how we can reproduce it? It started after updating realm-swift from 10.33.0 to 10.42.0 (realm-core 12.13.0 to 13.17.1 according to the release notes)

Crash log / stacktrace

Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib         	 0x00000001f82b1578 __pthread_kill (libsystem_kernel.dylib)
1   libsystem_c.dylib              	 0x00000001c081c178 abort (libsystem_c.dylib)
2   Realm                          	 0x000000010b19c23c realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&)
3   Realm                          	 0x000000010b19c570 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>&)
4   Realm                          	 0x000000010b19c3e0 realm::util::terminate_with_info(char const*, char const*, long, char const*, std::initializer_list<realm::util::Printable>&&)
5   Realm                          	 0x000000010b0048ec realm::SlabAlloc::free_block(unsigned long, realm::SlabAlloc::FreeBlock*)
6   Realm                          	 0x000000010b0046c4 realm::SlabAlloc::do_free(unsigned long, char*)
7   Realm                          	 0x000000010b0b1194 realm::Node::do_copy_on_write(unsigned long)
8   Realm                          	 0x000000010b0098b8 realm::Array::set(unsigned long, long long)
9   Realm                          	 0x000000010b0b1174 realm::Node::do_copy_on_write(unsigned long)
10  Realm                          	 0x000000010b0098b8 realm::Array::set(unsigned long, long long)
11  Realm                          	 0x000000010b0b1174 realm::Node::do_copy_on_write(unsigned long)
12  Realm                          	 0x000000010b0098b8 realm::Array::set(unsigned long, long long)
13  Realm                          	 0x000000010b0b1174 realm::Node::do_copy_on_write(unsigned long)
14  Realm                          	 0x000000010b0098b8 realm::Array::set(unsigned long, long long)
15  Realm                          	 0x000000010b0b1174 realm::Node::do_copy_on_write(unsigned long)
16  Realm                          	 0x000000010b0b2b3c realm::Obj& realm::Obj::set<double>(realm::ColKey, double, bool)
17  Realm                          	 0x000000010aed08f8 void realm::Object::set_property_value_impl<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, realm::Property const&, objc_object* __strong, realm::CreatePolicy, bool) (unique_ptr.h:290)
18  Realm                          	 0x000000010aed03f0 void realm::Object::set_property_value<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, realm::StringData, objc_object* __strong, realm::CreatePolicy) (object_accessor.hpp:48)
19  Realm                          	 0x000000010afefe58 (anonymous namespace)::ManagedSwiftValueStorage::set(objc_object*) (RLMSwiftValueStorage.mm:84)
20  Realm                          	 0x000000010afef8ac RLMSetSwiftValueStorage (RLMSwiftValueStorage.mm:157)
21  RealmSwift                     	 0x00000001082ecce8 specialized RealmProperty.value.setter (<compiler-generated>:0)
22  RealmSwift                     	 0x00000001082ec698 RealmProperty.value.setter (<compiler-generated>:0)
23  Common                   	         0x000000010d59c128 closure #1 in static Profile.updateLastSeenLocal() (<compiler-generated>:0)

Steps & Code to Reproduce

This is closure #1 in Profile.updateLastSeenLocal referenced in the stack trace

    try! realm.write {
      App.Data.profile.lastSeen.value = NSDate().timeIntervalSince1970
    }
@nicola-cab nicola-cab changed the title realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) Slab allocator crashes deleting a block Aug 24, 2023
@nicola-cab
Copy link
Member

Hello, thank you for reporting this, this seems compatible with the generic issue that tracks all the free list corruptions we have had so far (#6813). I'll add this new issue in there as well.

We are trying to understand what it is, that it might have caused a corruption in the free list. Unfortunately, at the moment we have no solution, since we haven't found a way to reproduce it. However, it seems your app is highly impacted by this, do you happen to have some more info to share with us? For example, what these apps that are crashing were doing when they were auto updated? Does your app use compactOnLauch=True?

Also, thanks for the range of realm core versions, I'll look in all the commits that went in and try to understand what could have caused such regression.

@alanipce
Copy link
Author

alanipce commented Aug 24, 2023

Our default Realm configuration uses a file based encrypted realm. We do provide a function to shouldCompactOnLaunch but it is used only for logging the Realm DB size, we always return false for compacting on launch.

Realm.Configuration(
        fileURL: fileURL,
        encryptionKey: encryptionKey,
        schemaVersion: schemaVersion,
        migrationBlock: env.performDatabaseMigrations(_:_:),
        shouldCompactOnLaunch: env.shouldCompactDatabaseOnLaunch(totalBytes:usedBytes:)
      )

So far I haven't been able to identify a common pattern in the crashes, it happens across the app when adding and updating entries in write transactions.

Do you have any recommendations for a temporary solution? would downgrading Realm cause other issues or is passing a value for compacting a potential cause?

@nicola-cab
Copy link
Member

At the moment we don't know what it is causing this, unfortunately. We have several ideas, but we haven't been able to identify the root cause of this issue. So I can't give you any advice that is based on some strong foundation.
We only know that for some user that was experiencing an issue similar to yours, he stopped doing compactOnLaunch and he stopped seeing crashes.
Does your app use sync?

@alanipce
Copy link
Author

No our app does not use the Realm sync feature.

@suhailpatel
Copy link
Contributor

suhailpatel commented Aug 29, 2023

If it's a data point, we are experiencing this issue and have not been able to reproduce reliably

We do not specify shouldCompactOnLaunch and do not use file encryption nor do we use realm sync and still encounter the same issue

For us, we also started seeing it in realm-swift 10.33.0 and we currently use realm-swift 10.38.0, so that's realm-core 12.13.0 to 13.9.0 according to the release notes, which maybe can narrow it down a little for bisecting

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

Successfully merging a pull request may close this issue.

4 participants