realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

[realm-core-10.3.2] Assertion failed: local_ndx < m_page_state.size() with (local_ndx, m_page_state.size()) = [1734, 1728]

Open junsolOh opened this issue 4 years ago • 7 comments

Goals

Occasionally Crash Occurs During ThreadSafeReference Initializer

Actual Results

/Users/realm/workspace/realm_realm-core_release_10.3.2/src/realm/util/encrypted_file_mapping.hpp:150: [realm-core-10.3.2] Assertion failed: local_ndx < m_page_state.size() with (local_ndx, m_page_state.size()) =  [1734, 1728]
0   Realm                               0x000000010a88cc3c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x000000010a88d0d8 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 388
2   Realm                               0x000000010a71b7c0 _ZZN5realm4util11FunctionRefIFvPNS_13BPlusTreeNodeEmEEC1IRZNKS_9BPlusTreeIxE3getEmEUlS3_mE_EEOT_ENUlPvS3_mE_8__invokeESD_S3_m + 0
3   Realm                               0x000000010a870ae0 _ZNSt3__16vectorIbNS_9allocatorIbEEE6resizeEmb + 0
4   Realm                               0x000000010a3a9e38 _ZN5realm4util26do_encryption_read_barrierEPKvmPFmPKcEPNS0_20EncryptedFileMappingE + 92
5   Realm                               0x000000010a64c084 _ZNK5realm9Allocator23translate_less_criticalEPNS0_14RefTranslationEm + 320
6   Realm                               0x000000010a3a9b24 _ZNK5realm9Allocator18translate_criticalEPNS0_14RefTranslationEm + 284
7   Realm                               0x000000010a3a9948 _ZNK5realm9Allocator9translateEm + 132
8   Realm                               0x000000010a3a987c _ZN5realm5Array13init_from_refEm + 60
9   Realm                               0x000000010a701f54 _ZN5realm5Group6attachEmbb + 88
10  Realm                               0x000000010a70a178 _ZN5realm5Group16advance_transactEmRNS_5_impl17NoCopyInputStreamEb + 252
11  Realm                               0x000000010a9d1200 _ZN5realm11Transaction29rollback_and_continue_as_readINS_5_impl23NullInstructionObserverEEEvPT_ + 696
12  Realm                               0x000000010a9ceb5c _ZN5realm5_impl11transaction6cancelERNS_11TransactionEPNS_14BindingContextE + 608
13  Realm                               0x000000010a5a80c8 -[RLMRealm cancelWriteTransaction] + 60
14  Realm                               0x000000010a5a886c -[RLMRealm dealloc] + 140
15  libobjc.A.dylib                     0x00000001baa787b0 2E47ABD7-2C5A-318D-8044-776883BCCCB6 + 157616
16  libobjc.A.dylib                     0x00000001baa78650 objc_autoreleasePoolPop + 212
17  libswiftObjectiveC.dylib            0x00000001cbdfaf3c $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 76
18  Cupix Capture Dev                   0x00000001006e6b84 $s8CPEngine9ICPRecordP17Cupix_Capture_DevE14saveToDatabase_12errorHandlery10RealmSwift0K0VSg_ys5Error_pcSgtFyycfU_ + 236
19  Cupix Capture Dev                   0x00000001004abde0 $sIeg_IeyB_TR + 52
20  libdispatch.dylib                   0x00000001a56dc24c 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 8780
21  libdispatch.dylib                   0x00000001a56dddb0 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 15792
22  libdispatch.dylib                   0x00000001a56e510c 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 45324
23  libdispatch.dylib                   0x00000001a56e5c5c 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 48220
24  libdispatch.dylib                   0x00000001a56efd78 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 89464
25  libsystem_pthread.dylib             0x00000001f12bb804 _pthread_wqthread + 276
26  libsystem_pthread.dylib             0x00000001f12c275c start_wqthread + 8!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected] 15:16:47.376660+0900 Cupix Capture Dev[1885:297456] /Users/realm/workspace/realm_realm-core_release_10.3.2/src/realm/util/encrypted_file_mapping.hpp:150: [realm-core-10.3.2] Assertion failed: local_ndx < m_page_state.size() with (local_ndx, m_page_state.size()) =  [1734, 1728]
0   Realm                               0x000000010a88cc3c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x000000010a88d0d8 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 388
2   Realm                               0x000000010a71b7c0 _ZZN5realm4util11FunctionRefIFvPNS_13BPlusTreeNodeEmEEC1IRZNKS_9BPlusTreeIxE3getEmEUlS3_mE_EEOT_ENUlPvS3_mE_8__invokeESD_S3_m + 0
3   Realm                               0x000000010a870ae0 _ZNSt3__16vectorIbNS_9allocatorIbEEE6resizeEmb + 0
4   Realm                               0x000000010a3a9e38 _ZN5realm4util26do_encryption_read_barrierEPKvmPFmPKcEPNS0_20EncryptedFileMappingE + 92
5   Realm                               0x000000010a64c084 _ZNK5realm9Allocator23translate_less_criticalEPNS0_14RefTranslationEm + 320
6   Realm                               0x000000010a3a9b24 _ZNK5realm9Allocator18translate_criticalEPNS0_14RefTranslationEm + 284
7   Realm                               0x000000010a3a9948 _ZNK5realm9Allocator9translateEm + 132
8   Realm                               0x000000010a3a987c _ZN5realm5Array13init_from_refEm + 60
9   Realm                               0x000000010a701f54 _ZN5realm5Group6attachEmbb + 88
10  Realm                               0x000000010a70a178 _ZN5realm5Group16advance_transactEmRNS_5_impl17NoCopyInputStreamEb + 252
11  Realm                               0x000000010a9d1200 _ZN5realm11Transaction29rollback_and_continue_as_readINS_5_impl23NullInstructionObserverEEEvPT_ + 696
12  Realm                               0x000000010a9ceb5c _ZN5realm5_impl11transaction6cancelERNS_11TransactionEPNS_14BindingContextE + 608
13  Realm                               0x000000010a5a80c8 -[RLMRealm cancelWriteTransaction] + 60
14  Realm                               0x000000010a5a886c -[RLMRealm dealloc] + 140
15  libobjc.A.dylib                     0x00000001baa787b0 2E47ABD7-2C5A-318D-8044-776883BCCCB6 + 157616
16  libobjc.A.dylib                     0x00000001baa78650 objc_autoreleasePoolPop + 212
17  libswiftObjectiveC.dylib            0x00000001cbdfaf3c $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 76
18  Cupix Capture Dev                   0x00000001006e6b84 $s8CPEngine9ICPRecordP17Cupix_Capture_DevE14saveToDatabase_12errorHandlery10RealmSwift0K0VSg_ys5Error_pcSgtFyycfU_ + 236
19  Cupix Capture Dev                   0x00000001004abde0 $sIeg_IeyB_TR + 52
20  libdispatch.dylib                   0x00000001a56dc24c 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 8780
21  libdispatch.dylib                   0x00000001a56dddb0 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 15792
22  libdispatch.dylib                   0x00000001a56e510c 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 45324
23  libdispatch.dylib                   0x00000001a56e5c5c 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 48220
24  libdispatch.dylib                   0x00000001a56efd78 0F3905E0-6720-3D08-9AE0-A43A8DA244C0 + 89464
25  libsystem_pthread.dylib             0x00000001f12bb804 _pthread_wqthread + 276
26  libsystem_pthread.dylib             0x00000001f12c275c start_wqthread + 8!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected].

Code Sample

static func writeSync<T : ThreadConfined>(
    obj: T,
    on queue: DispatchQueue = .realmQueue,
    realmConfiguration : Configuration? = nil,
    block: @escaping ((Realm, T?) throws -> Void)
  ) rethrows {

    let wrappedObj = ThreadSafeReference(to: obj)  <-- crashed
    
    try queue.sync {
      try autoreleasepool {
        let realm : Realm
        if let config = realmConfiguration {
          realm = try Realm(configuration: config)
        } else {
          realm = try Realm()
        }
        let obj = realm.resolve(wrappedObj)
        
        try realm.write {
          try block(realm, obj)
        }
      }
    }
  }

Version of Realm and Tooling

Realm framework version: 10.5.0

Xcode version: 12.3

iOS version: IOS 14.3

Dependency manager + version: pod 1.10.0

junsolOh avatar Jan 15 '21 02:01 junsolOh

Hi @junsolOh From looking at the stacktrace the issue looks related to the use of autoreleasepool. Where the Realm instance is being released while performing work.

leemaguire avatar Jan 15 '21 10:01 leemaguire

I'm going to close this issue because of no response from original reporter. If you're still seeing this error after incorporating Lee's comment, please feel free to respond.

ejm01 avatar Jan 29 '21 20:01 ejm01

Hello, I am getting a similar error after updating Realm from 5.1.0 to 10.5.1. There was no such mistake earlier.

Actual Results

/Users/usr/Library/Developer/Xcode/DerivedData/AppName-geoymsstyvtoahheikmvpgpjqsli/SourcePackages/checkouts/realm-core/src/realm/util/encrypted_file_mapping.hpp:150: [realm-core-10.3.3] Assertion failed: local_ndx < m_page_state.size() with (local_ndx, m_page_state.size()) =  [1036, 32]
0   AppName                                0x000000010385b400 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   AppName                                0x000000010385b7c8 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 316
2   AppName                                0x0000000103554a08 _ZN5realm4util19terminate_with_infoIJRmmEEEvPKciS4_S4_DpOT_ + 160
3   AppName                                0x000000010380a7ec _ZNK5realm4util20EncryptedFileMapping26get_local_index_of_addressEPKvm + 260
4   AppName                                0x000000010380a950 _ZN5realm4util20EncryptedFileMapping12read_barrierEPKvmPFmPKcE + 340
5   AppName                                0x0000000103321f70 _ZN5realm4util26do_encryption_read_barrierEPKvmPFmPKcEPNS0_20EncryptedFileMappingE + 72
6   AppName                                0x0000000103321150 _ZN5realm4util23encryption_read_barrierEPKvmPNS0_20EncryptedFileMappingEPFmPKcE + 80
7   AppName                                0x000000010332d600 _ZNK5realm9Allocator18translate_criticalEPNS0_14RefTranslationEm + 260
8   AppName                                0x000000010332478c _ZNK5realm9Allocator9translateEm + 92
9   AppName                                0x00000001034c82c0 _ZN5realm13BPlusTreeBase20create_root_from_refEm + 48
10  AppName                                0x00000001034c7754 _ZN5realm13BPlusTreeBase13init_from_refEm + 52
11  AppName                                0x0000000103575940 _ZN5realm3LstINS_6ObjKeyEEC2ERKS2_ + 456
12  AppName                                0x0000000103575b98 _ZN5realm3LstINS_6ObjKeyEEC1ERKS2_ + 40
13  AppName                                0x00000001035abb94 _ZN5realm6LnkLstC2ERKS0_ + 108
14  AppName                                0x00000001035abb14 _ZN5realm6LnkLstC1ERKS0_ + 40
15  AppName                                0x00000001035abaa4 _ZNSt3__1L11make_uniqueIN5realm6LnkLstEJRKS2_EEENS_11__unique_ifIT_E15__unique_singleEDpOT0_ + 68
16  AppName                                0x00000001035a707c _ZNK5realm6LnkLst14clone_linklistEv + 56
17  AppName                                0x000000010362dc00 _ZN5realm5QueryC2ERKS0_ + 404
18  AppName                                0x000000010362ded8 _ZN5realm5QueryC1ERKS0_ + 40
19  AppName                                0x000000010364b5fc _ZN5realm14ConstTableViewC2ENS_13ConstTableRefERNS_5QueryEmmm + 204
20  AppName                                0x000000010364b514 _ZN5realm9TableViewC2ENS_8TableRefERNS_5QueryEmmm + 116
21  AppName                                0x000000010363bf04 _ZN5realm9TableViewC1ENS_8TableRefERNS_5QueryEmmm + 80
22  AppName                                0x000000010363be5c _ZN5realm5Query8find_allEmmm + 92
23  AppName                                0x00000001030574bc _ZN5realm5_impl15ResultsNotifier3runEv + 484
24  AppName                                0x0000000103029170 _ZN5realm5_impl16RealmCoordinator19run_async_notifiersEv + 2808
25  AppName                                0x000000010302858c _ZN5realm5_impl16RealmCoordinator9on_changeEv + 32
26  AppName                                0x0000000102fcb3b0 _ZN5realm5_impl20ExternalCommitHelper6listenEv + 656
27  AppName                                0x0000000102fcf5ac _ZZN5realm5_impl20ExternalCommitHelperC1ERNS0_16RealmCoordinatorEENK3$_0clEv + 28
28  AppName                                0x0000000102fcf548 _ZNSt3__1L8__invokeIZN5realm5_impl20ExternalCommitHelperC1ERNS2_16RealmCoordinatorEE3$_0JEEEDTclclsr3std3__1E7forwardIT_Efp_Espclsr3std3__1E7forwardIT0_Efp0_EEEOS7_DpOS8_ + 28
29  AppName                                0x0000000102fcf4a8 _ZNSt3__1L16__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZN5realm5_impl20ExternalCommitHelperC1ERNS7_16RealmCoordinatorEE3$_0JEJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 32
30  AppName                                0x0000000102fceba4 _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN5realm5_impl20ExternalCommitHelperC1ERNS8_16RealmCoordinatorEE3$_0EEEEEPvSE_ + 116
31  libsystem_pthread.dylib             0x00000001e6c41b40 _pthread_start + 320
32  libsystem_pthread.dylib             0x00000001e6c4a768 thread_start + 8!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected] 13:21:12.569140+0100 AppName[16448:7055064] /Users/ivangonchar/Library/Developer/Xcode/DerivedData/AppName-geoymsstyvtoahheikmvpgpjqsli/SourcePackages/checkouts/realm-core/src/realm/util/encrypted_file_mapping.hpp:150: [realm-core-10.3.3] Assertion failed: local_ndx < m_page_state.size() with (local_ndx, m_page_state.size()) =  [1036, 32]
0   AppName                                0x000000010385b400 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   AppName                                0x000000010385b7c8 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 316
2   AppName                                0x0000000103554a08 _ZN5realm4util19terminate_with_infoIJRmmEEEvPKciS4_S4_DpOT_ + 160
3   AppName                                0x000000010380a7ec _ZNK5realm4util20EncryptedFileMapping26get_local_index_of_addressEPKvm + 260
4   AppName                                0x000000010380a950 _ZN5realm4util20EncryptedFileMapping12read_barrierEPKvmPFmPKcE + 340
5   AppName                                0x0000000103321f70 _ZN5realm4util26do_encryption_read_barrierEPKvmPFmPKcEPNS0_20EncryptedFileMappingE + 72
6   AppName                                0x0000000103321150 _ZN5realm4util23encryption_read_barrierEPKvmPNS0_20EncryptedFileMappingEPFmPKcE + 80
7   AppName                                0x000000010332d600 _ZNK5realm9Allocator18translate_criticalEPNS0_14RefTranslationEm + 260
8   AppName                                0x000000010332478c _ZNK5realm9Allocator9translateEm + 92
9   AppName                                0x00000001034c82c0 _ZN5realm13BPlusTreeBase20create_root_from_refEm + 48
10  AppName                                0x00000001034c7754 _ZN5realm13BPlusTreeBase13init_from_refEm + 52
11  AppName                                0x0000000103575940 _ZN5realm3LstINS_6ObjKeyEEC2ERKS2_ + 456
12  AppName                                0x0000000103575b98 _ZN5realm3LstINS_6ObjKeyEEC1ERKS2_ + 40
13  AppName                                0x00000001035abb94 _ZN5realm6LnkLstC2ERKS0_ + 108
14  AppName                                0x00000001035abb14 _ZN5realm6LnkLstC1ERKS0_ + 40
15  AppName                                0x00000001035abaa4 _ZNSt3__1L11make_uniqueIN5realm6LnkLstEJRKS2_EEENS_11__unique_ifIT_E15__unique_singleEDpOT0_ + 68
16  AppName                                0x00000001035a707c _ZNK5realm6LnkLst14clone_linklistEv + 56
17  AppName                                0x000000010362dc00 _ZN5realm5QueryC2ERKS0_ + 404
18  AppName                                0x000000010362ded8 _ZN5realm5QueryC1ERKS0_ + 40
19  AppName                                0x000000010364b5fc _ZN5realm14ConstTableViewC2ENS_13ConstTableRefERNS_5QueryEmmm + 204
20  AppName                                0x000000010364b514 _ZN5realm9TableViewC2ENS_8TableRefERNS_5QueryEmmm + 116
21  AppName                                0x000000010363bf04 _ZN5realm9TableViewC1ENS_8TableRefERNS_5QueryEmmm + 80
22  AppName                                0x000000010363be5c _ZN5realm5Query8find_allEmmm + 92
23  AppName                                0x00000001030574bc _ZN5realm5_impl15ResultsNotifier3runEv + 484
24  AppName                                0x0000000103029170 _ZN5realm5_impl16RealmCoordinator19run_async_notifiersEv + 2808
25  AppName                                0x000000010302858c _ZN5realm5_impl16RealmCoordinator9on_changeEv + 32
26  AppName                                0x0000000102fcb3b0 _ZN5realm5_impl20ExternalCommitHelper6listenEv + 656
27  AppName                                0x0000000102fcf5ac _ZZN5realm5_impl20ExternalCommitHelperC1ERNS0_16RealmCoordinatorEENK3$_0clEv + 28
28  AppName                                0x0000000102fcf548 _ZNSt3__1L8__invokeIZN5realm5_impl20ExternalCommitHelperC1ERNS2_16RealmCoordinatorEE3$_0JEEEDTclclsr3std3__1E7forwardIT_Efp_Espclsr3std3__1E7forwardIT0_Efp0_EEEOS7_DpOS8_ + 28
29  AppName                                0x0000000102fcf4a8 _ZNSt3__1L16__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZN5realm5_impl20ExternalCommitHelperC1ERNS7_16RealmCoordinatorEE3$_0JEJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 32
30  AppName                                0x0000000102fceba4 _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN5realm5_impl20ExternalCommitHelperC1ERNS8_16RealmCoordinatorEE3$_0EEEEEPvSE_ + 116
31  libsystem_pthread.dylib             0x00000001e6c41b40 _pthread_start + 320
32  libsystem_pthread.dylib             0x00000001e6c4a768 thread_start + 8!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected].
(lldb) 

Version of Realm and Tooling

Realm framework version: 10.5.1 Realm Database version 10.3.3

Xcode version: 12.3

iOS version: IOS 14.3 (iPhone 11)

Swift package manager

AdAvAn avatar Feb 07 '21 14:02 AdAvAn

@AdAvAn Are you able to reproduce this consistently? If so, could you share a project?

ejm01 avatar Feb 10 '22 21:02 ejm01

I'm experiencing the same issue in my open-source app (or well, users are experiencing the same issue, I'm not). I have not been able to reproduce this yet.

tijme avatar Feb 20 '22 12:02 tijme

@tijme please also post your stacktrace as it may not be related or it may provide additional information

bmunkholm avatar Feb 22 '22 07:02 bmunkholm

@junsolOh, @AdAvAn, @tijme, Is it still a problem with the latest Realm versions? If so - could you try to reproduce using release build instead of debug? In some cases it can help.

pavel-ship-it avatar May 31 '22 09:05 pavel-ship-it

Closing this issue due to its age and lack of response. If it persists on the latest version on Realm please open a new issue.

leemaguire avatar Aug 26 '22 10:08 leemaguire