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: backlink_ndx != not_found #7594

Closed
andrefmsilva opened this issue Apr 15, 2024 · 16 comments
Closed

Assertion failed: backlink_ndx != not_found #7594

andrefmsilva opened this issue Apr 15, 2024 · 16 comments
Assignees

Comments

@andrefmsilva
Copy link

SourcePackages/checkouts/realm-core/src/realm/array_backlink.cpp:129: [realm-core-14.4.1] Assertion failed: backlink_ndx != not_found
0    tvOS                        0x000000010659fdd8 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1    tvOS                        0x000000010659fdb8 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 308
2    tvOS                        0x000000010659fc84 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0
3    tvOS                        0x0000000105d7d95c _ZN5realm13ArrayBacklink6removeEmNS_6ObjKeyE + 508
4    tvOS                        0x0000000105f66450 _ZN5realm3Obj19remove_one_backlinkENS_6ColKeyENS_6ObjKeyE + 292
5    tvOS                        0x0000000105f622cc _ZNK5realm3Obj15remove_backlinkENS_6ColKeyENS_7ObjLinkERNS_12CascadeStateE + 524
6    tvOS                        0x0000000105f2aec8 _ZNK5realm18CollectionBaseImplINS_7LstBaseEE15remove_backlinkENS_6ColKeyENS_7ObjLinkERNS_12CascadeStateE + 100
7    tvOS                        0x0000000105f2cb18 _ZNK5realm3LstINS_5MixedEE14clear_backlinkEmRNS_12CascadeStateE + 276
8    tvOS                        0x0000000105f2c008 _ZNK5realm3LstINS_5MixedEE16remove_backlinksERNS_12CascadeStateE + 88
9    tvOS                        0x0000000105dcf96c _ZZN5realm7Cluster5eraseENS_6ObjKeyERNS_12CascadeStateEENK3$_6clENS_6ColKeyE + 1320
10   tvOS                        0x0000000105dbd5a8 _ZNK5realm5Table25for_each_and_every_columnIZNS_7Cluster5eraseENS_6ObjKeyERNS_12CascadeStateEE3$_6EEbT_ + 140
11   tvOS                        0x0000000105dbd360 _ZN5realm7Cluster5eraseENS_6ObjKeyERNS_12CascadeStateE + 420
12   tvOS                        0x0000000105ded8b4 _ZZN5realm16ClusterNodeInner5eraseENS_6ObjKeyERNS_12CascadeStateEENK3$_8clEPNS_11ClusterNodeERNS0_9ChildInfoE + 76
13   tvOS                        0x0000000105ded768 _ZN5realm16ClusterNodeInner7recurseImZNS0_5eraseENS_6ObjKeyERNS_12CascadeStateEE3$_8EET_RNS0_9ChildInfoET0_ + 200
14   tvOS                        0x0000000105de27b8 _ZN5realm16ClusterNodeInner7recurseImZNS0_5eraseENS_6ObjKeyERNS_12CascadeStateEE3$_8EET_S2_T0_ + 212
15   tvOS                        0x0000000105de26d8 _ZN5realm16ClusterNodeInner5eraseENS_6ObjKeyERNS_12CascadeStateE + 64
16   tvOS                        0x0000000105de5b78 _ZN5realm11ClusterTree5eraseENS_6ObjKeyERNS_12CascadeStateE + 248
17   tvOS                        0x00000001064cd51c _ZN5realm5Table16remove_recursiveERNS_12CascadeStateE + 716
18   tvOS                        0x00000001064d3a74 _ZN5realm5Table19batch_erase_objectsERNSt3__16vectorINS_6ObjKeyENS1_9allocatorIS3_EEEE + 332
19   tvOS                        0x00000001064fefbc _ZN5realm5_impl11TableFriend19batch_erase_objectsERNS_5TableERNSt3__16vectorINS_6ObjKeyENS4_9allocatorIS6_EEEE + 32
20   tvOS                        0x00000001064fee34 _ZN5realm9TableView5clearEv + 348
21   tvOS                        0x00000001060a9ea4 _ZN5realm7Results5clearEv + 252
22   tvOS                        0x0000000105b73d78 _ZZ36-[RLMResults deleteObjectsFromRealm]ENK4$_19clEv + 152
23   tvOS                        0x0000000105b73c60 _ZL24translateCollectionErrorIZ36-[RLMResults deleteObjectsFromRealm]E4$_19EDaOT_P8NSString + 36
24   tvOS                        0x0000000105b69f50 -[RLMResults deleteObjectsFromRealm] + 204
25   tvOS                        0x0000000105b4e6c8 -[RLMRealm deleteObjects:] + 308
26   tvOS                        0x0000000105ca6c68 $s10RealmSwift0A0V6deleteyyAA7ResultsVyxGSo13RLMObjectBaseCRbzAA0A15CollectionValueRzlF + 92
!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
Copy link

sync-by-unito bot commented Apr 15, 2024

➤ PM Bot commented:

Jira ticket: RCORE-2083

@andrefmsilva
Copy link
Author

I still get this crash in latest version

@nicola-cab
Copy link
Member

Does your realm config have automatically_handle_backlinks_in_migrations = true ?

@andrefmsilva
Copy link
Author

I'm using realm swift with default configs. I only set the classes that realm should use

@ironage
Copy link
Contributor

ironage commented Jun 12, 2024

@andrefmsilva thanks for reporting this.
I have tried unsuccessfully to reproduce this based on the stack trace that you provided. Could you share your schema with us? From what I can tell, this happens when clearing a Results that contains links to embedded objects which themselves have a list of mixed/any. There is a certain combination of what those embedded object links are pointing to that causes this crash but my guesses haven't yielded any crashes. Could you please help us narrow this down by describing what the link graph of objects looks like, or better yet, provide a repro case?

@andrefmsilva
Copy link
Author

hi @ironage i'm still testing but i think it got fixed in latest realm swift version.
I will close the issue and get back if i got the crash again

@andrefmsilva
Copy link
Author

andrefmsilva commented Jun 17, 2024

i got the crash again.

SourcePackages/checkouts/realm-core/src/realm/array_backlink.cpp:129: [realm-core-14.9.0] Assertion failed: backlink_ndx != not_found
0   RealmSwift                          0x0000000112005bb4 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   RealmSwift                          0x0000000112005b94 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 308
2   RealmSwift                          0x0000000112005a60 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0
3   RealmSwift                          0x0000000111767f34 _ZN5realm13ArrayBacklink6removeEmNS_6ObjKeyE + 508
4   RealmSwift                          0x0000000111961908 _ZN5realm3Obj19remove_one_backlinkENS_6ColKeyENS_6ObjKeyE + 292
5   RealmSwift                          0x000000011195d728 _ZNK5realm3Obj15remove_backlinkENS_6ColKeyENS_7ObjLinkERNS_12CascadeStateE + 524
6   RealmSwift                          0x00000001119253f4 _ZNK5realm18CollectionBaseImplINS_7LstBaseEE15remove_backlinkENS_6ColKeyENS_7ObjLinkERNS_12CascadeStateE + 100
7   RealmSwift                          0x00000001119270ac _ZNK5realm3LstINS_5MixedEE14clear_backlinkEmRNS_12CascadeStateE + 276
8   RealmSwift                          0x00000001119267f0 _ZNK5realm3LstINS_5MixedEE16remove_backlinksERNS_12CascadeStateE + 88
9   RealmSwift                          0x00000001117be3b8 _ZZN5realm7Cluster5eraseENS_6ObjKeyERNS_12CascadeStateEENK3$_6clENS_6ColKeyE + 1300
10  RealmSwift                          0x00000001117aa89c _ZNK5realm5Table25for_each_and_every_columnIZNS_7Cluster5eraseENS_6ObjKeyERNS_12CascadeStateEE3$_6EEbT_ + 140
11  RealmSwift                          0x00000001117aa654 _ZN5realm7Cluster5eraseENS_6ObjKeyERNS_12CascadeStateE + 420
12  RealmSwift                          0x00000001117e3218 _ZZN5realm16ClusterNodeInner5eraseENS_6ObjKeyERNS_12CascadeStateEENK3$_8clEPNS_11ClusterNodeERNS0_9ChildInfoE + 76
13  RealmSwift                          0x00000001117e30cc _ZN5realm16ClusterNodeInner7recurseImZNS0_5eraseENS_6ObjKeyERNS_12CascadeStateEE3$_8EET_RNS0_9ChildInfoET0_ + 200
14  RealmSwift                          0x00000001117d7ca0 _ZN5realm16ClusterNodeInner7recurseImZNS0_5eraseENS_6ObjKeyERNS_12CascadeStateEE3$_8EET_S2_T0_ + 212
15  RealmSwift                          0x00000001117d7bc0 _ZN5realm16ClusterNodeInner5eraseENS_6ObjKeyERNS_12CascadeStateE + 64
16  RealmSwift                          0x00000001117db060 _ZN5realm11ClusterTree5eraseENS_6ObjKeyERNS_12CascadeStateE + 248
17  RealmSwift                          0x0000000111f32378 _ZN5realm5Table16remove_recursiveERNS_12CascadeStateE + 716
18  RealmSwift                          0x0000000111871930 _ZN5realm5_impl11TableFriend16remove_recursiveERNS_5TableERNS_12CascadeStateE + 32
19  RealmSwift                          0x00000001118fc854 _ZN5realm3LstINS_6ObjKeyEE6do_setEmS1_ + 312
20  RealmSwift                          0x00000001118fc6a0 _ZN5realm3LstINS_6ObjKeyEE3setEmS1_ + 492
21  RealmSwift                          0x0000000111928cb4 _ZN5realm6LnkLst28create_and_set_linked_objectEm + 256
22  RealmSwift                          0x00000001120e33e4 _ZN5realm4List3setIRU8__strongKP11objc_object18RLMAccessorContextEEvRT0_mOT_NS_12CreatePolicyE + 156
23  RealmSwift                          0x00000001120e3328 __51-[RLMManagedArray replaceObjectAtIndex:withObject:]_block_invoke + 352
24  RealmSwift                          0x00000001120e67ac _ZL24translateCollectionErrorIRU8__strongU13block_pointerFvvEEDaOT_P8NSString + 44
25  RealmSwift                          0x00000001120e6a74 _ZL11changeArrayIZL11changeArrayP15RLMManagedArray16NSKeyValueChangemU13block_pointerFvvEE4$_22EvS1_S2_S4_OT_ + 536
26  RealmSwift                          0x00000001120e2244 _ZL11changeArrayP15RLMManagedArray16NSKeyValueChangemU13block_pointerFvvE + 72
27  RealmSwift                          0x00000001120e3138 -[RLMManagedArray replaceObjectAtIndex:withObject:] + 208
28  RealmSwift                          0x0000000111557f9c $s10RealmSwift4ListC7replace5index6objectySi_xtF + 376

@andrefmsilva andrefmsilva reopened this Jun 17, 2024
@andrefmsilva
Copy link
Author

andrefmsilva commented Jun 17, 2024

Models

public class GroupEntry: EmbeddedObject {
    @Persisted public var key: String
    @Persisted public var title: String
    @Persisted public var items: List<AnyRealmValue>
    @Persisted public var uuids: List<String>

    convenience init(key: String, title: String, items: any RealmCollection) {
        self.init()
        self.key = key
        self.title = title
        self.items.append(objectsIn: items.map { .object($0 as! Object) })
        uuids.append(objectsIn: items.value(forKey: "uuid") as! [String])
    }
}

public class ScreenGroupManager: Object {
    @Persisted(primaryKey: true) public var uuid: String

    @Persisted public var configHash: String
    @Persisted public var hasItems: Bool
    @Persisted public var staticGroups: List<GroupEntry>
    @Persisted public var dynamicGroups: List<GroupEntry>
}

crash here:

           groups.forEach { group in
                if let idx = manager.staticGroups.firstIndex(where: { $0.key == group.key }) {
                    manager.staticGroups.replace(index: idx, object: group) // HERE!
                } else {
                    manager.staticGroups.append(group)
                }
            }

@ironage
Copy link
Contributor

ironage commented Jun 17, 2024

@andrefmsilva thanks for the extra info there. Could you provide an example of the contents in GroupEntry.items? According to the stack trace, deleting the backlinks from this list is the part that causes the assertion. I'd be interested in any examples but here are some questions to help us narrow the search:

  • Does that list have links that point to the top level ScreenGroupManager object?
  • Does the list contain multiple/duplicate links to the same object?
  • Does the list contain links to various different classes, or just one class type?

It would be most helpful if you could narrow down which object in particular is causing the assertion and describe the contents of its list for us. Thank you for your patience as we work to find the source of this!

@andrefmsilva
Copy link
Author

andrefmsilva commented Jun 18, 2024

i will try to create a sample app but i can already respond some of the questions.

  • Does that list have links that point to the top level ScreenGroupManager object?
    No. I don't have any backlink to this models
  • Does the list contain multiple/duplicate links to the same object?
    No. Group entry can contain a unique entry for each object
  • Does the list contain links to various different classes, or just one class type?
    Yes and i think this is the problem. I use ScreenGroupManager to pre cache screen groups and it's crashing only for the screen that can contain GroupEntry with different class types. Please note that each GroupEntry can only contain one class type in the items property.

Structure example:

ScreenGroupManager {
   staticGroups = [
       GroupEntry.items = [
          Type1,
          Type1,
          Type1,
          Type1
        ],
      GroupEntry.items = [
          Type2,
          Type2,
          Type2,
          Type2
        ],
        GroupEntry.items = [
          Type3,
          Type3,
          Type3,
          Type3
        ],
        GroupEntry.items = [
          Type1,
          Type1,
          Type1,
          Type1
        ]
  ]
}

The app also crashes when i try to delete a ScreenGroupManager with this structure. For other screens where ScreenGroupManager contains GroupEntrywith same type it's working without crashes so far

@andrefmsilva
Copy link
Author

@ironage do you need logs from realm? i can enabled them and see if we get some extra info

@andrefmsilva
Copy link
Author

Screenshot 2024-06-18 at 17 05 44

I've tried some other methods to change the list but it still crashes

@ironage
Copy link
Contributor

ironage commented Jun 18, 2024

@andrefmsilva yes, logs would help us here if you don't mind sharing, please use the most verbose mode if possible. Is this app using realm sync? Can you share what the schema is of the Type1/Type2/Type3 classes? I'm specifically interested in any links to or from those objects.

@ironage
Copy link
Contributor

ironage commented Jul 16, 2024

Although we never got a full repro case here, I am fairly certain I have fixed the issue in #7830. @andrefmsilva please try out the fix and feel free to reopen if you still have issues.

@sync-by-unito sync-by-unito bot closed this as completed Jul 16, 2024
@andrefmsilva
Copy link
Author

Thanks @ironage
Any ETA for a release date of realm swift with updated core?

@tgoyne
Copy link
Member

tgoyne commented Jul 18, 2024

If no problems arise it will be tomorrow or early next week.

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

No branches or pull requests

4 participants