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 with thread.cpp:186: [realm-core-5.23.5] pthread_mutex_destroy() failed #6333

Closed
RetVal opened this issue Nov 6, 2019 · 4 comments · Fixed by #6382
Closed

Crash with thread.cpp:186: [realm-core-5.23.5] pthread_mutex_destroy() failed #6333

RetVal opened this issue Nov 6, 2019 · 4 comments · Fixed by #6382

Comments

@RetVal
Copy link

RetVal commented Nov 6, 2019

Goals

query results from realm, add notifications, remove notifications simultaneously.

Expected Results

Crash free

Actual Results

Run the demo about some minutes(maybe one minute), realm Crashed.

/Users/realm/workspace/realm_realm-core_release_5.23.5/src/realm/util/thread.cpp:186: [realm-core-5.23.5] pthread_mutex_destroy() failed
0   CrashRealm_Example                  0x000000010b2a270c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   CrashRealm_Example                  0x000000010b2a29c6 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 390
2   CrashRealm_Example                  0x000000010b2a32c0 _ZN5realm4util5Mutex11lock_failedEi + 0
3   CrashRealm_Example                  0x000000010b24d1be _ZN5realm5TableD2Ev + 814
4   CrashRealm_Example                  0x000000010ad26012 _ZNK5realm5Table10unbind_ptrEv + 178
5   CrashRealm_Example                  0x000000010ad25f5a _ZN5realm4util8bind_ptrINS_5TableEE6unbindEv + 42
6   CrashRealm_Example                  0x000000010ad25f25 _ZN5realm4util8bind_ptrINS_5TableEED2Ev + 21
7   CrashRealm_Example                  0x000000010ad25f05 _ZN5realm13BasicTableRefINS_5TableEED2Ev + 21
8   CrashRealm_Example                  0x000000010ad0ee05 _ZN5realm13BasicTableRefINS_5TableEED1Ev + 21
9   CrashRealm_Example                  0x000000010ac1c3d3 _ZN5realm4ListD2Ev + 51
10  CrashRealm_Example                  0x000000010ac1c435 _ZN5realm4ListD1Ev + 21
11  CrashRealm_Example                  0x000000010ad56f4a -[RLMManagedArray .cxx_destruct] + 90
12  libobjc.A.dylib                     0x00007fff50b96f02 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
13  libobjc.A.dylib                     0x00007fff50ba64b3 objc_destructInstance + 64
14  libobjc.A.dylib                     0x00007fff50bac94f -[NSObject dealloc] + 21
15  libobjc.A.dylib                     0x00007fff50bad0d6 _ZN11objc_object17sidetable_releaseEb + 174
16  CrashRealm_Example                  0x000000010ad42d07 _ZZ23RLMAddNotificationBlockIN5realm4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS5_P19RLMCollectionChangeP7NSErrorEbENUlRKNS0_19CollectionChangeSetESt13exception_ptrE_D2Ev + 39
17  CrashRealm_Example                  0x000000010ad3c2f5 _ZZ23RLMAddNotificationBlockIN5realm4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS5_P19RLMCollectionChangeP7NSErrorEbENUlRKNS0_19CollectionChangeSetESt13exception_ptrE_D1Ev + 21
18  CrashRealm_Example                  0x000000010ad47d81 _ZN5realm24CollectionChangeCallback4ImplIZ23RLMAddNotificationBlockINS_4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS7_P19RLMCollectionChangeP7NSErrorEbEUlRKNS_19CollectionChangeSetESt13exception_ptrE_ED2Ev + 49
19  CrashRealm_Example                  0x000000010ad47b05 _ZN5realm24CollectionChangeCallback4ImplIZ23RLMAddNotificationBlockINS_4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS7_P19RLMCollectionChangeP7NSErrorEbEUlRKNS_19CollectionChangeSetESt13exception_ptrE_ED1Ev + 21
20  CrashRealm_Example                  0x000000010ad475e9 _ZNSt3__120__shared_ptr_emplaceIN5realm24CollectionChangeCallback4ImplIZ23RLMAddNotificationBlockINS1_4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS9_P19RLMCollectionChangeP7NSErrorEbEUlRKNS1_19CollectionChangeSetESt13exception_ptrE_EENS_9allocatorISN_EEE16__on_zero_sharedEv + 41
21  CrashRealm_Example                  0x000000010ad3fbfa _ZNSt3__114__shared_count16__release_sharedEv + 58
22  CrashRealm_Example                  0x000000010ad3fb9f _ZNSt3__119__shared_weak_count16__release_sharedEv + 31
23  CrashRealm_Example                  0x000000010ad42ccc _ZNSt3__110shared_ptrIN5realm24CollectionChangeCallback4BaseEED2Ev + 44
24  CrashRealm_Example                  0x000000010ad42c95 _ZNSt3__110shared_ptrIN5realm24CollectionChangeCallback4BaseEED1Ev + 21
25  CrashRealm_Example                  0x000000010ad42c75 _ZN5realm24CollectionChangeCallbackD2Ev + 21
26  CrashRealm_Example                  0x000000010ad3c2d5 _ZN5realm24CollectionChangeCallbackD1Ev + 21
27  CrashRealm_Example                  0x000000010abf295e _ZN5realm5_impl18CollectionNotifier8CallbackD2Ev + 62
28  CrashRealm_Example                  0x000000010abef3a5 _ZN5realm5_impl18CollectionNotifier8CallbackD1Ev + 21
29  CrashRealm_Example                  0x000000010abef70c _ZN5realm5_impl18CollectionNotifier15remove_callbackEy + 732
30  CrashRealm_Example                  0x000000010abece22 _ZN5realm17NotificationTokenD2Ev + 114
31  CrashRealm_Example                  0x000000010abecfb5 _ZN5realm17NotificationTokenD1Ev + 21
32  CrashRealm_Example                  0x000000010ad3b6c6 -[RLMCancellationToken .cxx_destruct] + 38
33  libobjc.A.dylib                     0x00007fff50b96f02 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
34  libobjc.A.dylib                     0x00007fff50ba64b3 objc_destructInstance + 64
35  libobjc.A.dylib                     0x00007fff50bac94f -[NSObject dealloc] + 21
36  libobjc.A.dylib                     0x00007fff50bad0d6 _ZN11objc_object17sidetable_releaseEb + 174
37  CrashRealm_Example                  0x000000010abc7aa3 __32-[RxViewController __notifyJob:]_block_invoke + 275
38  CrashRealm_Example                  0x000000010b079d49 -[RxScheduler performAsCurrentScheduler:] + 505
39  CrashRealm_Example                  0x000000010b076f66 __31-[RxRunLoopScheduler schedule:]_block_invoke + 86
40  CoreFoundation                      0x00007fff23bb204c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
41  CoreFoundation                      0x00007fff23bb17b8 __CFRunLoopDoBlocks + 312
42  CoreFoundation                      0x00007fff23bac61e __CFRunLoopRun + 1246
43  CoreFoundation                      0x00007fff23babe16 CFRunLoopRunSpecific + 438
44  CrashRealm_Example                  0x000000010b0764bf _ZL32__RxRunLoopSchedulerRunLoopEntryPv + 2303
45  libsystem_pthread.dylib             0x00007fff51c04d36 _pthread_start + 125
46  libsystem_pthread.dylib             0x00007fff51c0158f thread_start + 15!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to help@realm.io.2019-11-06 18:40:54.707181+0800 CrashRealm_Example[45886:3038269] /Users/realm/workspace/realm_realm-core_release_5.23.5/src/realm/util/thread.cpp:186: [realm-core-5.23.5] pthread_mutex_destroy() failed
0   CrashRealm_Example                  0x000000010b2a270c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   CrashRealm_Example                  0x000000010b2a29c6 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 390
2   CrashRealm_Example                  0x000000010b2a32c0 _ZN5realm4util5Mutex11lock_failedEi + 0
3   CrashRealm_Example                  0x000000010b24d1be _ZN5realm5TableD2Ev + 814
4   CrashRealm_Example                  0x000000010ad26012 _ZNK5realm5Table10unbind_ptrEv + 178
5   CrashRealm_Example                  0x000000010ad25f5a _ZN5realm4util8bind_ptrINS_5TableEE6unbindEv + 42
6   CrashRealm_Example                  0x000000010ad25f25 _ZN5realm4util8bind_ptrINS_5TableEED2Ev + 21
7   CrashRealm_Example                  0x000000010ad25f05 _ZN5realm13BasicTableRefINS_5TableEED2Ev + 21
8   CrashRealm_Example                  0x000000010ad0ee05 _ZN5realm13BasicTableRefINS_5TableEED1Ev + 21
9   CrashRealm_Example                  0x000000010ac1c3d3 _ZN5realm4ListD2Ev + 51
10  CrashRealm_Example                  0x000000010ac1c435 _ZN5realm4ListD1Ev + 21
11  CrashRealm_Example                  0x000000010ad56f4a -[RLMManagedArray .cxx_destruct] + 90
12  libobjc.A.dylib                     0x00007fff50b96f02 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
13  libobjc.A.dylib                     0x00007fff50ba64b3 objc_destructInstance + 64
14  libobjc.A.dylib                     0x00007fff50bac94f -[NSObject dealloc] + 21
15  libobjc.A.dylib                     0x00007fff50bad0d6 _ZN11objc_object17sidetable_releaseEb + 174
16  CrashRealm_Example                  0x000000010ad42d07 _ZZ23RLMAddNotificationBlockIN5realm4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS5_P19RLMCollectionChangeP7NSErrorEbENUlRKNS0_19CollectionChangeSetESt13exception_ptrE_D2Ev + 39
17  CrashRealm_Example                  0x000000010ad3c2f5 _ZZ23RLMAddNotificationBlockIN5realm4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS5_P19RLMCollectionChangeP7NSErrorEbENUlRKNS0_19CollectionChangeSetESt13exception_ptrE_D1Ev + 21
18  CrashRealm_Example                  0x000000010ad47d81 _ZN5realm24CollectionChangeCallback4ImplIZ23RLMAddNotificationBlockINS_4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS7_P19RLMCollectionChangeP7NSErrorEbEUlRKNS_19CollectionChangeSetESt13exception_ptrE_ED2Ev + 49
19  CrashRealm_Example                  0x000000010ad47b05 _ZN5realm24CollectionChangeCallback4ImplIZ23RLMAddNotificationBlockINS_4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS7_P19RLMCollectionChangeP7NSErrorEbEUlRKNS_19CollectionChangeSetESt13exception_ptrE_ED1Ev + 21
20  CrashRealm_Example                  0x000000010ad475e9 _ZNSt3__120__shared_ptr_emplaceIN5realm24CollectionChangeCallback4ImplIZ23RLMAddNotificationBlockINS1_4ListEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS9_P19RLMCollectionChangeP7NSErrorEbEUlRKNS1_19CollectionChangeSetESt13exception_ptrE_EENS_9allocatorISN_EEE16__on_zero_sharedEv + 41
21  CrashRealm_Example                  0x000000010ad3fbfa _ZNSt3__114__shared_count16__release_sharedEv + 58
22  CrashRealm_Example                  0x000000010ad3fb9f _ZNSt3__119__shared_weak_count16__release_sharedEv + 31
23  CrashRealm_Example                  0x000000010ad42ccc _ZNSt3__110shared_ptrIN5realm24CollectionChangeCallback4BaseEED2Ev + 44
24  CrashRealm_Example                  0x000000010ad42c95 _ZNSt3__110shared_ptrIN5realm24CollectionChangeCallback4BaseEED1Ev + 21
25  CrashRealm_Example                  0x000000010ad42c75 _ZN5realm24CollectionChangeCallbackD2Ev + 21
26  CrashRealm_Example                  0x000000010ad3c2d5 _ZN5realm24CollectionChangeCallbackD1Ev + 21
27  CrashRealm_Example                  0x000000010abf295e _ZN5realm5_impl18CollectionNotifier8CallbackD2Ev + 62
28  CrashRealm_Example                  0x000000010abef3a5 _ZN5realm5_impl18CollectionNotifier8CallbackD1Ev + 21
29  CrashRealm_Example                  0x000000010abef70c _ZN5realm5_impl18CollectionNotifier15remove_callbackEy + 732
30  CrashRealm_Example                  0x000000010abece22 _ZN5realm17NotificationTokenD2Ev + 114
31  CrashRealm_Example                  0x000000010abecfb5 _ZN5realm17NotificationTokenD1Ev + 21
32  CrashRealm_Example                  0x000000010ad3b6c6 -[RLMCancellationToken .cxx_destruct] + 38
33  libobjc.A.dylib                     0x00007fff50b96f02 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
34  libobjc.A.dylib                     0x00007fff50ba64b3 objc_destructInstance + 64
35  libobjc.A.dylib                     0x00007fff50bac94f -[NSObject dealloc] + 21
36  libobjc.A.dylib                     0x00007fff50bad0d6 _ZN11objc_object17sidetable_releaseEb + 174
37  CrashRealm_Example                  0x000000010abc7aa3 __32-[RxViewController __notifyJob:]_block_invoke + 275
38  CrashRealm_Example                  0x000000010b079d49 -[RxScheduler performAsCurrentScheduler:] + 505
39  CrashRealm_Example                  0x000000010b076f66 __31-[RxRunLoopScheduler schedule:]_block_invoke + 86
40  CoreFoundation                      0x00007fff23bb204c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
41  CoreFoundation                      0x00007fff23bb17b8 __CFRunLoopDoBlocks + 312
42  CoreFoundation                      0x00007fff23bac61e __CFRunLoopRun + 1246
43  CoreFoundation                      0x00007fff23babe16 CFRunLoopRunSpecific + 438
44  CrashRealm_Example                  0x000000010b0764bf _ZL32__RxRunLoopSchedulerRunLoopEntryPv + 2303
45  libsystem_pthread.dylib             0x00007fff51c04d36 _pthread_start + 125
46  libsystem_pthread.dylib             0x00007fff51c0158f thread_start + 15!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to help@realm.io.

Steps to Reproduce

Reproduce demo

Version of Realm and Tooling

ProductName:    Mac OS X
ProductVersion: 10.15.1
BuildVersion:   19B88

/Applications/Xcode.app/Contents/Developer
Xcode 11.2
Build version 11B52

/usr/local/bin/pod
1.7.1
(not in use here)

/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)

/usr/local/bin/carthage
0.31.2
(not in use here)

/usr/bin/git
git version 2.21.0 (Apple Git-122.2)
@jsflax
Copy link
Contributor

jsflax commented Nov 6, 2019

I've tried to run your demo, but it appears to have some kind of private pod dependency.

@tgoyne
Copy link
Member

tgoyne commented Nov 6, 2019

The private pods are present in the repro repo, so just skipping pod install and opening the xcworkspace there works.

I can reproduce the crash running the app. It appears to be related to destroying notification tokens on a different thread than they were created on at the same time as the Realm they were obtained from is being closed. This is something that's supposed to work.

@tgoyne
Copy link
Member

tgoyne commented Nov 6, 2019

I've made a PR which I think fixes this: realm/realm-core#3460.

@anton-plebanovich
Copy link

anton-plebanovich commented Apr 22, 2020

Not sure if related but I have a crash on 4.3.2 version that looks familiar. This fix was delivered in a 4.3.1 so there might be more cases or it isn't related.

Crashed thread:

0  libsystem_kernel.dylib         0x196366efc __pthread_kill + 8
1  libsystem_pthread.dylib        0x1962868b8 pthread_kill + 228
2  libsystem_c.dylib              0x196216a74 abort + 104
3  Realm                          0x107aecc3c realm::util::terminate(char const*, char const*, long) + 10
4  Realm                          0x107aecf08 _hidden#15080_ + 716
5  Realm                          0x107aed080 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 328
6  Realm                          0x107aed848 realm::util::Mutex::lock_failed(int) + 82
7  Realm                          0x107aa389c realm::Table::~Table() + 620
8  Realm                          0x107808830 realm::List::~List() + 1737 (__hidden#706_:1737)
9  libobjc.A.dylib                0x196294130 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
10 libobjc.A.dylib                0x1962a6f80 objc_destructInstance + 92
11 libobjc.A.dylib                0x1962ade44 _objc_rootDealloc + 52
12 libobjc.A.dylib                0x1962af3f8 objc_release + 136
13 Realm                          0x107857ea8 _hidden#4619_ + 2649 (__hidden#43_:2649)
14 libobjc.A.dylib                0x196294130 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
15 libobjc.A.dylib                0x1962a6f80 objc_destructInstance + 92
16 libobjc.A.dylib                0x1962ade44 _objc_rootDealloc + 52
17 libobjc.A.dylib                0x1962af3f8 objc_release + 136
18 libobjc.A.dylib                0x196294130 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
19 libobjc.A.dylib                0x1962a6f80 objc_destructInstance + 92
20 libobjc.A.dylib                0x1962ade44 _objc_rootDealloc + 52
21 Realm                          0x1078625c4 _hidden#4984_ + 92 (__hidden#5024_:92)
22 libobjc.A.dylib                0x1962af3f8 objc_release + 136
23 libswiftCore.dylib             0x1a3eab4c4 swift_arrayDestroy + 84
24 libswiftCore.dylib             0x1a3c4599c _ContiguousArrayStorage.__deallocating_deinit + 48
25 libswiftCore.dylib             0x1a3eb5bd4 _swift_release_dealloc + 36
26 libswiftCore.dylib             0x1a3eb4a3c swift_release + 32
...

Second not crashed thread:

0  libsystem_kernel.dylib         0x196366d1c __psynch_mutexwait + 8
1  libsystem_pthread.dylib        0x19628a868 _pthread_mutex_firstfit_lock_wait + 92
2  libsystem_pthread.dylib        0x19628a7d8 _pthread_mutex_firstfit_lock_slow + 260
3  libc++.1.dylib                 0x1963ef1c4 std::__1::recursive_mutex::lock() + 16
4  Realm                          0x1079cd764 realm::SubtableColumnBase::update_from_parent(unsigned long) + 52
5  Realm                          0x107ab6868 realm::Table::update_from_parent(unsigned long) + 204
6  Realm                          0x1079d4284 realm::Group::update_refs(unsigned long, unsigned long) + 148
7  Realm                          0x1079e25a4 realm::SharedGroup::commit_and_continue_as_read() + 200
8  Realm                          0x107830290 realm::_impl::RealmCoordinator::commit_write(realm::Realm&) + 1511 (__hidden#221_:1511)
9  Realm                          0x10790307c realm::Realm::commit_transaction() + 724 (__hidden#10246_:724)
10 Realm                          0x1078d2494 _hidden#8203_ + 663 (__hidden#8364_:663)
11 RealmSwift                     0x107d7c23c Realm.write<A>(withoutNotifying:_:) + 280 (Realm.swift:280)
...

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
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.

7 participants