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

Crash: Database inaccessible after period of time. #7164

Closed
ragu-pdx opened this issue Mar 4, 2021 · 9 comments
Closed

Crash: Database inaccessible after period of time. #7164

ragu-pdx opened this issue Mar 4, 2021 · 9 comments
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community Reproduction-Required

Comments

@ragu-pdx
Copy link

ragu-pdx commented Mar 4, 2021

!!! MANDATORY TO FILL OUT !!!

Goals

Writing data to iOS Realm database in a stable manner over time and not have underlying database file corruption

Expected Results

No Crash

Actual Results

Crash Entitled: please_report_this_issue_in_github_realm_realm_core

libsystem_kernel.dylib
__pthread_kill
libsystem_c.dylib
abort
Realm
please_report_this_issue_in_github_realm_realm_core
Realm
realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)
Realm
realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&)
Realm
realm::Spec::init(realm::MemRef)
Realm
realm::Spec::init(unsigned long)
Realm
realm::Table::init(unsigned long, realm::ArrayParent*, unsigned long, bool, bool)
Realm
realm::Group::create_table_accessor(unsigned long)
Realm
realm::Group::do_get_table(unsigned long)
Realm
realm::Object realm::Object::get_for_primary_key<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, std::__1::shared_ptr<realm::Realm> const&, realm::ObjectSchema const&, objc_object* __strong) group.hpp:991
Realm
RLMGetObject RLMObjectStore.mm:220
RealmSwift
RealmSwift.Realm.object<A, B where A: __C.RealmSwiftObject>(ofType: A.Type, forPrimaryKey: B) -> A? Realm.swift:673
Radiata
closure #1 () -> () in Radiata.BluetoothService.peripheral(_: __C.PBPeripheral, readerResults: Foundation.Data) -> () BluetoothService.swift:291
Radiata
Radiata.RunLoopThread.(execute in _25C052638766C1F8EA472462436432EF)(Radiata.(BlockWrapper in _25C052638766C1F8EA472462436432EF)) -> () RunLoopThread.swift:69
Radiata
@objc Radiata.RunLoopThread.(execute in _25C052638766C1F8EA472462436432EF)(Radiata.(BlockWrapper in _25C052638766C1F8EA472462436432EF)) -> () <compiler-generated>:0
Foundation
__NSThreadPerformPerform
Radiata
closure #1 () -> Swift.Bool in closure #1 () -> () in Radiata.RunLoopThread.main() -> () RunLoopThread.swift:34
Radiata
partial apply forwarder for reabstraction thunk helper from @callee_guaranteed () -> (@unowned Swift.Bool, @error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out Swift.Bool, @error @owned Swift.Error) <compiler-generated>:0
libswiftObjectiveC.dylib
ObjectiveC.autoreleasepool<A>(invoking: () throws -> A) throws -> A
Radiata
closure #1 () -> () in Radiata.RunLoopThread.main() -> () RunLoopThread.swift:32
Radiata
reabstraction thunk helper from @callee_guaranteed () -> (@error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error) <compiler-generated>:0
Radiata
partial apply forwarder for reabstraction thunk helper from @callee_guaranteed () -> (@error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error) <compiler-generated>:0
libswiftObjectiveC.dylib
ObjectiveC.autoreleasepool<A>(invoking: () throws -> A) throws -> A
Radiata
@objc Radiata.RunLoopThread.main() -> () RunLoopThread.swift:25
Foundation
__NSThread__start__
2021-03-02 19:19:43.790 [E] (User+Realm:28) Realm error retrieving persistent realm db: Unable to open a realm at path '/var/mobile/Containers/Data/Application/0156404F-71A1-498C-8BA6-FBE32FF3CC3E/Library/Application Support/Realm/A/1613511625DA57FB41-persistent.realm': Realm file initial open failed Path:Exception backtrace:
0   Realm                               0x000000010370c56c _ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ + 60
1   Realm                               0x000000010364fd18 _ZN5realm9SlabAlloc11attach_fileERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERNS0_6ConfigE + 2964
2   Realm                               0x00000001036f18fc _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 3156
3   Realm                               0x00000001036f437c _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 244
4   Realm                               0x00000001036f8fc8 _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 392
5   Realm                               0x00000001039c5b40 _ZN5realm5_impl16RealmCoordinator7open_dbEv + 1344
6   Realm                               0x00000001039c4884 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_5Realm6ConfigERNSt3__110shared_ptrIS2_EENS_4util8OptionalINS_9VersionIDEEERNS8_17CheckedUniqueLockE + 68
7   Realm                               0x00000001039c46c0 _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigENS_4util8OptionalINS_9VersionIDEEE + 400
8   Realm                               0x0000000103a3f270 _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 120
9   Realm                               0x000000010362dc30 +[RLMRealm realmWithConfiguration:queue:error:] + 956
10  RealmSwift                          0x0000000104000fc0 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 88
11  Radiata                             0x0000000102948080 Radiata + 393344
12  Radiata                             0x0000000102913530 Radiata + 177456
13  Radiata                             0x0000000102926904 Radiata + 256260
14  Radiata                             0x0000000102926988 Radiata + 256392
15  Foundation                          0x00000001a108bb90 7698BF3E-0CF6-31C0-85E9-562714F01276 + 1551248
16  CoreFoundation                      0x000000019fc7176c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661356
17  CoreFoundation                      0x000000019fc71668 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661096
18  CoreFoundation                      0x000000019fc70960 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 657760
19  CoreFoundation                      0x000000019fc6aa8c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 633484
20  CoreFoundation                      0x000000019fc6a21c CFRunLoopRunSpecific + 600
21  Foundation                          0x00000001a0f19df0 7698BF3E-0CF6-31C0-85E9-562714F01276 + 36336
22  Radiata                             0x0000000102925ec0 Radiata + 253632
23  Radiata                             0x0000000102926c10 Radiata + 257040
24  libswiftObjectiveC.dylib            0x00000001c619bf30 $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 64
25  Radiata                             0x0000000102925d50 Radiata + 253264
26  Radiata                             0x00000001028f2fdc Radiata + 45020
27  Radiata                             0x0000000102926bb8 Radiata + 256952
28  libswiftObjectiveC.dylib            0x00000001c619bf30 $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 64
29  Radiata                             0x0000000102926064 Radiata + 254052
30  Foundation                          0x00000001a108ba34 7698BF3E-0CF6-31C0-85E9-562714F01276 + 1550900
31  libsystem_pthread.dylib             0x00000001eb7a3cb0 _pthread_start + 320
32  libsystem_pthread.dylib             0x00000001eb7ac778 thread_start + 8.
2021-03-02 19:19:43.803 [E] (User+Realm:29) 
0   Radiata                             0x0000000102949590 Radiata + 398736
1   SwiftyBeaver                        0x00000001041ee8d8 $s12SwiftyBeaverAAC4info___4line7contextyypyXK_S2SSiypSgtFZypyXEfu_TA + 20
2   SwiftyBeaver                        0x00000001041ef75c $s12SwiftyBeaverAAC13dispatch_send5level7message6thread4file8function4line7contextyAB5LevelO_ypyXKS3SSiypSgtFZ04$s12ab55AAC6custom5level7message4file8function4line7contextyAB5L27O_ypyXKS2SSiypSgtFZypyXEfu_ypIgr_Tf1ncnnnnnn_nTf4nnnnnndn_n + 2020
3   SwiftyBeaver                        0x00000001041ed9f0 $s12SwiftyBeaverAAC6custom5level7message4file8function4line7contextyAB5LevelO_ypyXKS2SSiypSgtFZ + 124
4   SwiftyBeaver                        0x00000001041ed968 $s12SwiftyBeaverAAC7verbose___4line7contextyypyXK_S2SSiypSgtFZTm + 72
5   SwiftyBeaver                        0x00000001041ed914 $s12SwiftyBeaverAAC5error___4line7contextyypyXK_S2SSiypSgtFZ + 36
6   Radiata                             0x00000001029481cc Radiata + 393676
7   Radiata                             0x0000000102913530 Radiata + 177456

Steps for others to Reproduce

Is not reliably reproduced - Related to this ticket

Code Sample

Code snippets in 7088

Version of Realm and Tooling

Realm framework version: Latest

Realm Object Server version: N/A

Xcode version: 12.4

iOS/OSX version: iOS 14.4

Dependency manager + version: Cocoapods latest

@pavel-ship-it
Copy link
Contributor

Hi @ragu-pth ,
The code snippet in #7088 looks fine.
Could you show how you opening the Realm with that configuration? I'm asking as error did appear in [RLMRealm realmWithConfiguration:queue:error:]
Is it in a main thread? did you pass a queue during initialization?

@ragu-pdx
Copy link
Author

ragu-pdx commented Mar 5, 2021

@pavel-ship-it Thank you for your reply. The function private func realm(storageType: DatabaseService.StorageType) -> Realm? can be called within different threads, but in these cases, it is only being called within a single persistent NSThread that is made at startup instead of using dispatch_queues.

@leemaguire
Copy link
Contributor

@ragu-pth as you are calling private func realm(storageType: DatabaseService.StorageType) -> Realm? from different threads the issue is most likely related to another thread having a lock on the Realm file that you want to open. The solution here would be to have your Realm bound to only one thread at a time. This can get messy fast, it would be better to use GCD for this kind of scenario. You can open a Realm on a dispatch_queue and also open a Realm asynchronously if needs be.

@ragu-pdx
Copy link
Author

ragu-pdx commented Mar 22, 2021

@leemaguire The creation and retrieval of the configuration objects is thread-safe, as both creation and retrieval are blocked by an access semaphore, as seen at the top of the file submitted in the #7088 ticket. Realm itself is billed as thread-safe, and we've never run into such issues since using this type of logic since Realm 5.x. Did something change in Realm 10.x?

This issue is also happening in these cases on first launch, on the very first thread call, so it also isn't an issue due to being accessed from multiple threads. All the errors I've submitted are it being called within the single, same thread.

The dispatch queues are abstracting away from threads, and run more risk as they can open Realms across an unknown number of threads in the pool. We've had issues with that in the past (Realm 4.x+), which moved us to having Realm on a dedicated background thread and main thread, so it's only used on a handful of threads for the lifetime of the app.

As an aside, are there any paid Technical Support packages Realm provides and that you can point me to to escalate this issue? While an exceedingly rare problem, data integrity is paramount in our application and so I'd like to get to the root cause of this.

@leemaguire
Copy link
Contributor

'The dispatch queues are abstracting away from threads, and run more risk as they can open Realms across an unknown number of threads in the pool.' - This isn't true a Realm is bound to one concurrency context.

@ragu-pth Realm Cocoa is built with Dispatch Queues in mind, and serial queues for that matter. So I would recommend utilising GCD. Looking back at your semaphore in #7088 I'm not sure that it properly achieves the locking mechanism you are after. Especially if you are doing things with threads a semaphore won't always guarantee mutual exclusion.

@ragu-pdx
Copy link
Author

Especially if you are doing things with threads a semaphore won't always guarantee mutual exclusion.

Why wouldn't this be the case, especially if it is a semaphore of 1 and essentially operating like a lock? We've never had an issue with this in the past, whereas the GCD has let to multiple issues Example & Example #2. These issues almost destroyed that product in the past as several customers were experiencing the issue with no real traceability, and necessitated a complete rewrite where we used a single thread to manage access to the database. What can you tell me about the fixes that have been implemented since then to ensure that using GCD won't cause those same issues today?

Also, where can I find information on other service level packages you offer besides the community issue submission? We are utilizing this in a healthtech company and want to get an appropriate level of support for the industry.

@ianpward
Copy link

hey @ragu-pth - Product for Realm here. If you'd like to drop me an email at [email protected] - I'd love to hear about your use case and we can discuss how we can better support you

@dianaafanador3
Copy link
Contributor

@ragu-pdx Any updates on this issue, Have you contacted @ianpward regarding your issue?

@sync-by-unito sync-by-unito bot changed the title Crash: please_report_this_issue_in_github_realm_realm_core. Database inaccessible after period of time. Crash: Database inaccessible after period of time. Oct 5, 2021
@sync-by-unito sync-by-unito bot added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Nov 9, 2021
@no-response
Copy link

no-response bot commented Nov 23, 2021

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Nov 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community Reproduction-Required
Projects
None yet
Development

No branches or pull requests

5 participants