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

'Assertion failed' - Fatal crash when initialising Realm #5707

Closed
n-doton opened this issue Aug 3, 2022 · 12 comments · Fixed by #5715
Closed

'Assertion failed' - Fatal crash when initialising Realm #5707

n-doton opened this issue Aug 3, 2022 · 12 comments · Fixed by #5715
Assignees

Comments

@n-doton
Copy link

n-doton commented Aug 3, 2022

When initialising flexibleSync with a realm schema object, our app crashes unexpectedly with the following stacktrace:

0   librealm_dart.dylib                 0x000000014ddfe608 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   librealm_dart.dylib                 0x000000014ddfe550 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   librealm_dart.dylib                 0x000000014dc24364 _ZN5realm4sync10ClientImpl10Connection28change_state_to_disconnectedEv + 216
3   librealm_dart.dylib                 0x000000014dc23fe0 _ZN5realm4sync10ClientImpl10Connection10disconnectERKNS0_16SessionErrorInfoE + 552
4   librealm_dart.dylib                 0x000000014dc1f2c0 _ZN5realm4sync10ClientImpl10Connection30close_due_to_client_side_errorENSt3__110error_codeEb + 220
5   librealm_dart.dylib                 0x000000014dc2682c _ZN5realm4sync10ClientImpl7Session22on_integration_failureERKNS0_20IntegrationExceptionENS0_18DownloadBatchStateE + 184
6   librealm_dart.dylib                 0x000000014dbf7518 _ZN5realm4sync10ClientImpl7Session29process_pending_flx_bootstrapEv + 904
7   librealm_dart.dylib                 0x000000014dc1e2b4 _ZN5realm4sync10ClientImpl7Session8activateEv + 584
8   librealm_dart.dylib                 0x000000014dc1df80 _ZN5realm4sync10ClientImpl10Connection16activate_sessionENSt3__110unique_ptrINS1_7SessionENS3_14default_deleteIS5_EEEE + 216
9   librealm_dart.dylib                 0x000000014dbf5d90 _ZN5realm4sync14SessionWrapper9actualizeENSt3__15tupleIJNS0_16ProtocolEnvelopeENS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEtEEE + 940
10  librealm_dart.dylib                 0x000000014dbf5630 _ZN5realm4sync10ClientImpl39actualize_and_finalize_session_wrappersEv + 372
11  librealm_dart.dylib                 0x000000014dc29eb8 _ZN5realm4util7network7Trigger8ExecOperIZNS_4sync10ClientImplC1ENS4_12ClientConfigEE3$_0E19recycle_and_executeEv + 52
12  librealm_dart.dylib                 0x000000014dc787d0 _ZN5realm4util7network7Service4Impl3runEv + 408
13  librealm_dart.dylib                 0x000000014dbfa7cc _ZN5realm4sync6Client3runEv + 36
14  librealm_dart.dylib                 0x000000014db36a04 _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN5realm5_impl10SyncClientC1ENS2_INS7_4util6LoggerENS4_ISB_EEEERKNS7_16SyncClientConfigENS_8weak_ptrIKNS7_11SyncManagerEEEEUlvE0_EEEEEPvSN_ + 44
15  libsystem_pthread.dylib             0x0000000192f3f878 _pthread_start + 320

We're initialising Realm using the following:

  final AppConfiguration appConfig = AppConfiguration('app-id-goes-here');
  final App app = App(appConfig);

  final Credentials anonCredentials = Credentials.anonymous();
  final User currentUser = await app.logIn(anonCredentials);

  final Configuration config = Configuration.flexibleSync(
    currentUser,
    <SchemaObject>[Model.schema],
    path: 'flex.realm',
  );

  final Realm realm = Realm(config);

The crash seems to occur after the first run of the app from a restart or sleep cycle of my machine. No logs are displayed in the App Services logs section. I understand that the stacktrace instructed us to post the report on the realm-core issues page however, as realm-dart is in beta we are assuming it'll be an issue with this repository.

Thanks in advance.

@nielsenko
Copy link
Contributor

Good call. I suspect this is the same issue that causes hot-reloads to crash (see realm/realm-dart#728).

Could you try to use:

 final User currentUser = app.currentUser ?? await app.logIn(anonCredentials);

@n-doton
Copy link
Author

n-doton commented Aug 3, 2022

Good call. I suspect this is the same issue that causes hot-reloads to crash (see realm/realm-dart#728).

Could you try to use:

 final User currentUser = app.currentUser ?? await app.logIn(anonCredentials);

Thanks for the quick response! Unfortunately, this change results in the same crash.

@n-doton n-doton closed this as completed Aug 3, 2022
@n-doton n-doton reopened this Aug 3, 2022
@nielsenko
Copy link
Contributor

nielsenko commented Aug 3, 2022

Could you try running it with Dart 2.18+, ie. Flutter beta channel?

@jbreams jbreams transferred this issue from realm/realm-dart Aug 3, 2022
@jbreams jbreams self-assigned this Aug 3, 2022
@n-doton
Copy link
Author

n-doton commented Aug 4, 2022

The issue still persists with SDK version 2.18.0-271.4. The app ran fine the first time I ran it this morning. Subsequent runs suffer the same crash in the original post.

@nielsenko
Copy link
Contributor

@n-doton Thank you for trying it out with dart 2.18, but we believe it is an issue in realm-core. We will get back to you.

@jbreams
Copy link
Contributor

jbreams commented Aug 4, 2022

Hi, @n-doton, yes I think this is a bug in realm-core. I think there's an exception integrating state from the server that's getting applied before the sync client is able to connect to the server and the logic for handling disconnects due to an error is not being called appropriately. If you turn on trace level logging in the sync client, you may be able to see what the error while applying state is. I'm working on a fix for how errors are handled while not yet connected and will keep you posted.

@nielsenko
Copy link
Contributor

nielsenko commented Aug 4, 2022

@n-doton To turn on the trace @jbreams is talking about, you can do:

  Realm.logger
    ..level = RealmLogLevel.trace
    ..onRecord.listen((event) {
      print(event); // or whatever
    });

before opening the realm

@n-doton
Copy link
Author

n-doton commented Aug 5, 2022

@nielsenko After some trial and error, I managed to get the following in the console:

flutter: [DEBUG] Realm: Realm sync client ([realm-core-12.1.0])
flutter: [DEBUG] Realm: Realm sync client ([realm-core-12.1.0])
flutter: [DEBUG] Realm: Realm sync client ([realm-core-12.1.0])
flutter: [DEBUG] Realm: Realm sync client ([realm-core-12.1.0])
flutter: [DEBUG] Realm: Realm sync client ([realm-core-12.1.0])
flutter: [DEBUG] Realm: Supported protocol versions: 2-6
flutter: [DEBUG] Realm: Supported protocol versions: 2-6
flutter: [DEBUG] Realm: Supported protocol versions: 2-6
flutter: [DEBUG] Realm: Supported protocol versions: 2-6
flutter: [DEBUG] Realm: Supported protocol versions: 2-6
flutter: [DEBUG] Realm: Supported protocol versions: 2-6
flutter: [DEBUG] Realm: Platform: macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
flutter: [DEBUG] Realm: Platform: macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
flutter: [DEBUG] Realm: Platform: macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
flutter: [DEBUG] Realm: Platform: macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
flutter: [DEBUG] Realm: Platform: macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
flutter: [DEBUG] Realm: Platform: macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
flutter: [DEBUG] Realm: Build mode: Release
flutter: [DEBUG] Realm: Build mode: Release
flutter: [DEBUG] Realm: Build mode: Release
flutter: [DEBUG] Realm: Build mode: Release
flutter: [DEBUG] Realm: Build mode: Release
flutter: [DEBUG] Realm: Build mode: Release
flutter: [DEBUG] Realm: Config param: one_connection_per_session = true
flutter: [DEBUG] Realm: Config param: one_connection_per_session = true
flutter: [DEBUG] Realm: Config param: one_connection_per_session = true
flutter: [DEBUG] Realm: Config param: one_connection_per_session = true
flutter: [DEBUG] Realm: Config param: one_connection_per_session = true
flutter: [DEBUG] Realm: Config param: one_connection_per_session = true
flutter: [DEBUG] Realm: Config param: connect_timeout = 120000000 ms
flutter: [DEBUG] Realm: Config param: connect_timeout = 120000000 ms
flutter: [DEBUG] Realm: Config param: connect_timeout = 120000000 ms
flutter: [DEBUG] Realm: Config param: connect_timeout = 120000000 ms
flutter: [DEBUG] Realm: Config param: connect_timeout = 120000000 ms
flutter: [DEBUG] Realm: Config param: connect_timeout = 120000000 ms
flutter: [DEBUG] Realm: Config param: connection_linger_time = 30000 ms
flutter: [DEBUG] Realm: Config param: connection_linger_time = 30000 ms
flutter: [DEBUG] Realm: Config param: connection_linger_time = 30000 ms
flutter: [DEBUG] Realm: Config param: connection_linger_time = 30000 ms
flutter: [DEBUG] Realm: Config param: connection_linger_time = 30000 ms
flutter: [DEBUG] Realm: Config param: connection_linger_time = 30000 ms
flutter: [DEBUG] Realm: Config param: ping_keepalive_period = 60000 ms
flutter: [DEBUG] Realm: Config param: ping_keepalive_period = 60000 ms
flutter: [DEBUG] Realm: Config param: ping_keepalive_period = 60000 ms
flutter: [DEBUG] Realm: Config param: ping_keepalive_period = 60000 ms
flutter: [DEBUG] Realm: Config param: ping_keepalive_period = 60000 ms
flutter: [DEBUG] Realm: Config param: ping_keepalive_period = 60000 ms
flutter: [DEBUG] Realm: Config param: pong_keepalive_timeout = 120000 ms
flutter: [DEBUG] Realm: Config param: pong_keepalive_timeout = 120000 ms
flutter: [DEBUG] Realm: Config param: pong_keepalive_timeout = 120000 ms
flutter: [DEBUG] Realm: Config param: pong_keepalive_timeout = 120000 ms
flutter: [DEBUG] Realm: Config param: pong_keepalive_timeout = 120000 ms
flutter: [DEBUG] Realm: Config param: pong_keepalive_timeout = 120000 ms
flutter: [DEBUG] Realm: Config param: fast_reconnect_limit = 60000 ms
flutter: [DEBUG] Realm: Config param: fast_reconnect_limit = 60000 ms
flutter: [DEBUG] Realm: Config param: fast_reconnect_limit = 60000 ms
flutter: [DEBUG] Realm: Config param: fast_reconnect_limit = 60000 ms
flutter: [DEBUG] Realm: Config param: fast_reconnect_limit = 60000 ms
flutter: [DEBUG] Realm: Config param: fast_reconnect_limit = 60000 ms
flutter: [DEBUG] Realm: Config param: disable_upload_compaction = false
flutter: [DEBUG] Realm: Config param: disable_upload_compaction = false
flutter: [DEBUG] Realm: Config param: disable_upload_compaction = false
flutter: [DEBUG] Realm: Config param: disable_upload_compaction = false
flutter: [DEBUG] Realm: Config param: disable_upload_compaction = false
flutter: [DEBUG] Realm: Config param: disable_upload_compaction = false
flutter: [DEBUG] Realm: Config param: disable_sync_to_disk = false
flutter: [DEBUG] Realm: Config param: disable_sync_to_disk = false
flutter: [DEBUG] Realm: Config param: disable_sync_to_disk = false
flutter: [DEBUG] Realm: Config param: disable_sync_to_disk = false
flutter: [DEBUG] Realm: Config param: disable_sync_to_disk = false
flutter: [DEBUG] Realm: Config param: disable_sync_to_disk = false
flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '
flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '
flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '
flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '
flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '
flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '

Please let me know if there is anything else I can do to help.

@nielsenko
Copy link
Contributor

nielsenko commented Aug 5, 2022

Hmm.. it looks as if your are subscribed 6 times to the logger. Could you structure your code, so that the listen call is not called repeatedly? Also, could you increase the log level to RealmLogLevel.trace?

Can you confirm that it dies immediately after:

flutter: [DEBUG] Realm: User agent string: 'RealmSync/12.1.0 (macOS Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64)  '

or did you omit some trace?

@n-doton
Copy link
Author

n-doton commented Aug 5, 2022

It was firing 6 times in my previous post, sorry about that! That was the last trace before the app exited. I'm unable to get the logger to log anymore after several attempts. The app exists with nothing in the stacktrace other than the stack in the original post.

Please could you confirm that the logger in the correct place, as shown in this example?

  final AppConfiguration appConfig = AppConfiguration('app-id-goes-here');
  final App app = App(appConfig);

  final Credentials anonCredentials = Credentials.anonymous();
  final User currentUser = await app.logIn(anonCredentials);

  final Configuration config = Configuration.flexibleSync(
    currentUser,
    <SchemaObject>[Model.schema],
    path: 'flex.realm',
  );

  Realm.logger
    ..level = RealmLogLevel.trace
    ..onRecord.listen((event) {
      print(event);
    });

  final Realm realm = Realm(config);

Thanks in advance.

Update: I got it to log again, the content is the exact same as my previous log.

@n-doton
Copy link
Author

n-doton commented Aug 12, 2022

Hi, I'm guessing this fix will be available in the next release. Is it possible to get an ETA on when this might be live? Thanks in advance.

@nielsenko
Copy link
Contributor

We normally don't give ETAs, but the release of realm-core version 12.6.0 (which includes this fix) is tentatively scheduled for Monday. For you to benefit we need to roll a release of the Flutter SDK as well, which I guess will happen Wednesday. But remember, these are not promises, more like wishful thinking on a Friday afternoon.

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

3 participants