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 in dart due to debug output when app is being torn down #7969

Closed
sync-by-unito bot opened this issue Aug 8, 2024 · 3 comments · Fixed by #7985
Closed

Crash in dart due to debug output when app is being torn down #7969

sync-by-unito bot opened this issue Aug 8, 2024 · 3 comments · Fixed by #7985
Assignees

Comments

@sync-by-unito
Copy link

sync-by-unito bot commented Aug 8, 2024

There is a crash that is occurring in DB::close_internal() when a Dart app is being torn down because the Logger instance has already been destroyed when the PersistedSyncMetadataManager is destroyed. It only happens if the debug level is set to something higher than info.

The issue is here: https://github.com/realm/realm-core/blob/master/src/realm/db.cpp#L2045-L2046


From slack conversation: https://mongodb.slack.com/archives/C010R3CMP3N/p1723112587976859

Does this ring a bell? Happens consistently on process exit when setting trace level to something finer than INFO in a test using realm-core 14.11.0.

/Users/runner/work/realm-dart/realm-dart/packages/realm_dart/src/realm-core/src/realm/util/thread.cpp:177: [realm-core-14.11.0] pthread_mutex_lock() failed: Invalid mutex object provided
0   librealm_dart.dylib                 0x000000011497ae8c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 32
1   librealm_dart.dylib                 0x000000011497ae04 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 396
2   librealm_dart.dylib                 0x000000011497ac78 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0
3   librealm_dart.dylib                 0x000000011497b484 _ZN5realm4util5Mutex11lock_failedEi + 132
4   librealm_dart.dylib                 0x0000000114976870 _ZN5realm4util12StderrLogger6do_logERKNS0_11LogCategoryENS2_5LevelERKNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEE + 276
5   librealm_dart.dylib                 0x0000000114803870 _ZN5realm8DBLogger6do_logERKNS_4util11LogCategoryENS2_5LevelERKNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEE + 480
6   librealm_dart.dylib                 0x000000011453dfb0 _ZN5realm4util6Logger6do_logIJEEEvRKNS0_11LogCategoryENS3_5LevelEPKcDpOT_ + 80
7   librealm_dart.dylib                 0x00000001147fd930 _ZN5realm2DB14close_internalENSt3__111unique_lockINS_4util17InterprocessMutexEEEb + 564
8   librealm_dart.dylib                 0x00000001147fb9c8 _ZN5realm2DB5closeEb + 168
9   librealm_dart.dylib                 0x00000001147fd52c _ZN5realm2DBD2Ev + 24
10  librealm_dart.dylib                 0x0000000114590fa4 _ZN5realm5_impl16RealmCoordinatorD2Ev + 920
11  librealm_dart.dylib                 0x0000000114634b34 _ZN12_GLOBAL__N_128PersistedSyncMetadataManagerD0Ev + 84
12  librealm_dart.dylib                 0x0000000114601838 _ZN5realm3app3AppD2Ev + 244
13  librealm_dart.dylib                 0x000000011460e370 _ZNSt3__16vectorINS_4pairINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEN5realm4util7FlatMapIS7_NS_10shared_ptrINS8_3app3AppEEENS_4lessIvEENS0_INS1_IS7_SE_EENS5_ISH_EEEEEEEENS5_ISL_EEE22__base_destruct_at_endB8ue170006EPSL_ + 156
14  librealm_dart.dylib                 0x0000000114600238 _ZN5realm4util7FlatMapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS1_IS8_NS2_10shared_ptrINS_3app3AppEEENS2_4lessIvEENS2_6vectorINS2_4pairIS8_SC_EENS6_ISH_EEEEEESE_NSF_INSG_IS8_SK_EENS6_ISL_EEEEED1Ev + 32
15  libsystem_c.dylib                   0x0000000185a872e8 __cxa_finalize_ranges + 476
16  libsystem_c.dylib                   0x0000000185a87070 exit + 44
17  dart                                0x0000000104764fd4 dart + 233428
18  dart                                0x000000010475bf50 dart + 196432
19  dart                                0x000000010475af84 dart + 192388
20  dyld                                0x000000018583f154 start + 2476
!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

This is a minimal reproduction:

import 'package:realm_dart/realm.dart';

void main(List<String> arguments) async {
  Realm.logger.setLogLevel(LogLevel.trace);
  final app = App(AppConfiguration('dummy'));
  // following throws since app doesn't exist,
  // but notice the crash on exit
  final user = await app.logIn(Credentials.anonymous());
}
Copy link
Author

sync-by-unito bot commented Aug 8, 2024

➤ PM Bot commented:

Jira ticket: RCORE-2234

Copy link
Author

sync-by-unito bot commented Aug 15, 2024

➤ michael-wb commented:

I have been trying to reproduce the crash using a Flutter app, but I haven't been able to reproduce it.
I have a fix ready for review that addresses this problem, but I cannot verify it in dart/flutter. I believe this issue was also seen in JS, so I will see if someone from that SDK team would be able to try to reproduce the issue.

Copy link
Author

sync-by-unito bot commented Aug 21, 2024

➤ michael-wb commented:

I also created a test program (crash_test.cpp) in Core that reproduces this problem - the issue is present regardless of whether or the RealmFFI library is loaded dynamically or statically linked.
Also verified that the changes from PR #7985 fixes this crash as well.

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

Successfully merging a pull request may close this issue.

1 participant