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

[macOS] Crash: Assertion failed #1396

Closed
sbenmeddour opened this issue Sep 7, 2023 · 11 comments
Closed

[macOS] Crash: Assertion failed #1396

sbenmeddour opened this issue Sep 7, 2023 · 11 comments

Comments

@sbenmeddour
Copy link

sbenmeddour commented Sep 7, 2023

What happened?

A bug happened!

Repro steps

I don't know how to reproduce it, it happens randomly

Version

Flutter 3.10.6 - Dart 3.0.6

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

macOS 13.2.1 (M2 chip)

Code snippets

No response

Stacktrace of the exception/crash you're getting

/Users/runner/work/realm-dart/realm-dart/src/realm-core/src/realm/alloc_slab.cpp:542: [realm-core-13.17.2] Assertion failed: ref + size <= next->first with (ref, size, next->first, next->second, get_file_path_for_assertions()) =  [48411896, 56, 48411896, 56, "***path/to/realm-file.realm***"]
0   librealm_dart.dylib                 0x000000010114dde8 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   librealm_dart.dylib                 0x000000010114dd30 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 400
2   librealm_dart.dylib                 0x0000000100fbb36c _ZN5realm9SlabAlloc10free_blockEmPNS0_9FreeBlockE + 0
3   librealm_dart.dylib                 0x0000000100fbb138 _ZN5realm9SlabAlloc7do_freeEmPc + 1736
4   librealm_dart.dylib                 0x0000000101068f18 _ZN5realm4Node16do_copy_on_writeEm + 320
5   librealm_dart.dylib                 0x0000000100fc0568 _ZN5realm5Array3setEmx + 124
6   librealm_dart.dylib                 0x0000000101068ef8 _ZN5realm4Node16do_copy_on_writeEm + 288
7   librealm_dart.dylib                 0x0000000100fc0568 _ZN5realm5Array3setEmx + 124
8   librealm_dart.dylib                 0x0000000101068ef8 _ZN5realm4Node16do_copy_on_writeEm + 288
9   librealm_dart.dylib                 0x0000000100fc0568 _ZN5realm5Array3setEmx + 124
10  librealm_dart.dylib                 0x0000000101106534 _ZN5realm5Table24allocate_sequence_numberEv + 120
11  librealm_dart.dylib                 0x000000010110ccc4 _ZN5realm5Table30create_object_with_primary_keyERKNS_5MixedEONS_11FieldValuesENS0_10UpdateModeEPb + 932
12  librealm_dart.dylib                 0x0000000100d1d3f4 realm_object_get_or_create_with_primary_key + 204
13  ???                                 0x0000000118d86dc8 0x0 + 4711804360
14  ???                                 0x000000028cbb64b8 0x0 + 10951025848
15  ???                                 0x000000028c18b2e4 0x0 + 10940363492
16  ???                                 0x000000028c18898c 0x0 + 10940352908
17  ???                                 0x00000001549139a8 0x0 + 5713770920
18  ???                                 0x000000028cebc0c8 0x0 + 10954195144
19  ???                                 0x000000028cebc46c 0x0 + 10954196076
20  ???                                 0x000000011c4d7754 0x0 + 4769806164
21  ???                                 0x000000028c199ebc 0x0 + 10940423868
22  ???                                 0x000000011b87c558 0x0 + 4756850008
23  ???                                 0x0000000177cf8438 0x0 + 6305055800
24  ???                                 0x000000011d68c3b4 0x0 + 4788372404
25  ???                                 0x00000001690b9248 0x0 + 6057333320
26  ???                                 0x000000028c18d1b4 0x0 + 10940371380
27  ???                                 0x000000011b804acc 0x0 + 4756359884
28  ???                                 0x0000000118d88210 0x0 + 4711809552
29  ???                                 0x000000011b87c558 0x0 + 4756850008
30  ???                                 0x0000000177cf8438 0x0 + 6305055800
31  ???                                 0x000000011d68c3b4 0x0 + 4788372404
32  ???                                 0x00000001690b9248 0x0 + 6057333320
33  ???                                 0x000000028c18d1b4 0x0 + 10940371380
34  ???                                 0x000000011d6b55e4 0x0 + 4788540900
35  ???                                 0x000000011d697374 0x0 + 4788417396
36  ???                                 0x000000028ced06a4 0x0 + 10954278564
37  ???                                 0x0000000118d834b8 0x0 + 4711789752
38  FlutterMacOS                        0x0000000107935200 _ZN4dart9DartEntry10InvokeCodeERKNS_4CodeEmRKNS_5ArrayES6_PNS_6ThreadE + 324
39  FlutterMacOS                        0x000000010793504c _ZN4dart9DartEntry14InvokeFunctionERKNS_8FunctionERKNS_5ArrayES6_m + 264
40  FlutterMacOS                        0x0000000107935960 _ZN4dart9DartEntry14InvokeCallableEPNS_6ThreadERKNS_8FunctionERKNS_5ArrayES8_ + 332
41  FlutterMacOS                        0x0000000107d49dcc Dart_InvokeClosure + 928
42  FlutterMacOS                        0x0000000107643a60 _ZN5tonic18DartMicrotaskQueue13RunMicrotasksEv + 164
43  FlutterMacOS                        0x000000010708d6c0 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 296
44  FlutterMacOS                        0x0000000107096220 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 52
45  CoreFoundation                      0x000000018c54354c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
46  CoreFoundation                      0x000000018c5431f4 __CFRunLoopDoTimer + 940
47  CoreFoundation                      0x000000018c542d4c __CFRunLoopDoTimers + 356
48  CoreFoundation                      0x000000018c528734 __CFRunLoopRun + 1896
49  CoreFoundation                      0x000000018c527878 CFRunLoopRunSpecific + 612
50  FlutterMacOS                        0x00000001070964b8 _ZN3fml17MessageLoopDarwin3RunEv + 184
51  FlutterMacOS                        0x000000010708d48c _ZN3fml15MessageLoopImpl5DoRunEv + 60
52  FlutterMacOS                        0x0000000107094580 _ZNSt21_LIBCPP_ABI_NAMESPACE14__thread_proxyB6v15000INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN3fml6ThreadC1ERKNS_8functionIFvRKNS8_12ThreadConfigEEEESC_E3$_0EEEEEPvSJ_ + 228
53  libsystem_pthread.dylib             0x000000018c44a06c _pthread_start + 148
54  libsystem_pthread.dylib             0x000000018c444e2c thread_start + 8
!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2

Relevant log output

No response

@nielsenko
Copy link
Contributor

@sbenmeddour I suspect this is related to realm/realm-core#6922

@sbenmeddour
Copy link
Author

All i can see, is that the crash happens every time when i try to insert objects after executing a large delete block before

@nielsenko
Copy link
Contributor

nielsenko commented Sep 7, 2023

Are you saying you can reproduce this consistently?

@sbenmeddour
Copy link
Author

Yes, i tried 3 times 5 minutes ago and i got the crash every time

@nielsenko
Copy link
Contributor

Are you able to create a stand-alone reproduction, or describe in more details how/when it happens? Or perhaps even give us access to your code-base?

@sbenmeddour
Copy link
Author

I am making a small reproduction sample. if I can't achieve to reproduce the crash with it, i will extract some blocks from my code

@sbenmeddour
Copy link
Author

I'm back with news: I know the reason to make it crash

Short description: Open two realms in different isolates. (lets call them Realm 1 and Realm 2)
The crash happens if you try to add and delete in different isolates at the same time

Notes: The crash happens only if i use writeAsync (not write) and does not occur if i am deleting and writing on the same isolate

(maybe async write transactions are not isolate safe, or i'm not using it right)

For better visibility i created a gist with a sample app with two buttons (delete, insert). You just have to tap on them quickly 2 times to make it crash

SAMPLE CODE

@nielsenko
Copy link
Contributor

@sbenmeddour I can replicate the crash on my machine. Thank you so much for your effort and dedication 🙏 . I'll investigate this further with members of the realm core team tomorrow.

nielsenko added a commit to nielsenko/slab_alloc that referenced this issue Sep 7, 2023
@sbenmeddour
Copy link
Author

Thank you for your quick response. It's a pleasure to have such support from your team

@nielsenko
Copy link
Contributor

@sbenmeddour It is a blessing to have users such as you 🥇

I have reduced your reproduction to:

import 'dart:isolate';

import 'package:realm_dart/realm.dart';

part 'slab_alloc2.g.dart';

@RealmModel()
class _Stuff {
  late int id;
}

final realm = Realm(Configuration.local([Stuff.schema]));

Future<void> main(List<String> arguments) async {
  Realm.logger.level = RealmLogLevel.all;
  Isolate.run(() async {
    while (true) {
      await realm.writeAsync(() {
        realm.addAll(List.generate(100000, (i) => Stuff(i)));
      });
    }
  });
  while (true) {
    await realm.writeAsync(() {
      realm.deleteAll<Stuff>();
    });
  }
}

@nielsenko
Copy link
Contributor

Fixed by realm/realm-core#6962

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