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 on object update or delete #6585

Closed
bodnar-dan opened this issue May 8, 2023 · 7 comments · Fixed by #6638
Closed

Crash on object update or delete #6585

bodnar-dan opened this issue May 8, 2023 · 7 comments · Fixed by #6638
Assignees
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community Waiting-For-Reporter Waiting for more information from the reporter before we can proceed

Comments

@bodnar-dan
Copy link

bodnar-dan commented May 8, 2023

SDK and version

SDK : realm-swift
Version: 10.35.1

Observations

  • How frequent do the crash occur?
    • Some users encountered the crash. Once happening, it will always happen when the user tries to update or delete that specific object.
  • Does it happen in production or during dev/test?
    • In production
  • Can the crash be reproduced by you?
    • No
  • Can you provide instructions for how we can reproduce it?
    • N/A

Crash log / stacktrace

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x7674 __pthread_kill + 8
1  libsystem_pthread.dylib        0x71ac pthread_kill + 268
2  libsystem_c.dylib              0x20c8c abort + 180
3  [APP]                    0x8d573c realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 147 (terminate.cpp:147)
4  [APP]                    0x8d5a7c realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) + 142 (terminate.cpp:142)
5  [APP]                    0x8d57f8 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 152 (terminate.cpp:152)
6  [APP]                    0x6568d4 realm::ArrayBacklink::erase(unsigned long) + 139 (array_backlink.cpp:139)
7  [APP]                    0x656894 realm::ArrayBacklink::remove(unsigned long, realm::ObjKey) + 715 (array.hpp:715)
8  [APP]                    0x6dc590 realm::Obj::remove_one_backlink(realm::ColKey, realm::ObjKey) + 1792 (obj.cpp:1792)
9  [APP]                    0x6dc9f8 realm::Obj::remove_backlink(realm::ColKey, realm::ObjLink, realm::CascadeState&) const + 1978 (obj.cpp:1978)
10 [APP]                    0x689008 realm::Dictionary::remove_backlinks(realm::CascadeState&) const + 209 (dictionary.hpp:209)
11 [APP]                    0x66b00c realm::Cluster::erase(realm::ObjKey, realm::CascadeState&) + 841 (cluster.cpp:841)
12 [APP]                    0x679794 realm::ClusterNodeInner::erase(realm::ObjKey, realm::CascadeState&)::$_7::operator()(realm::ClusterNode*, realm::ClusterNodeInner::ChildInfo&) const + 456 (cluster_tree.cpp:456)
13 [APP]                    0x67461c realm::ClusterNodeInner::erase(realm::ObjKey, realm::CascadeState&) + 256 (cluster_tree.cpp:256)
14 [APP]                    0x677354 realm::ClusterTree::erase(realm::ObjKey, realm::CascadeState&) + 1025 (cluster_tree.cpp:1025)
15 [APP]                    0x89dac4 realm::Table::remove_recursive(realm::CascadeState&) + 171 (wrap_iter.h:171)
16 [APP]                    0x8a07dc realm::Table::remove_object(realm::ObjKey) + 3411 (table.cpp:3411)
17 [APP]                    0x6d7ad0 realm::Obj::remove() + 188 (obj.cpp:188)
18 [APP]                    0x4a495c RLMDeleteObjectFromRealm + 181 (RLMObjectStore.mm:181)
19 [APP]                    0x25cc0c closure #1 in closure #1 in ProjectDAO.delete(_:) + 4300475404 (<compiler-generated>:4300475404)
20 [APP]                    0x25e0e0 partial apply for closure #1 in closure #1 in ProjectDAO.delete(_:) + 4300480736 (<compiler-generated>:4300480736)
21 [APP]                    0x60ab28 Realm.write<A>(withoutNotifying:_:) + 256 (Realm.swift:256)
22 [APP]                    0x25c748 closure #1 in ProjectDAO.delete(_:) + 101 (ProjectDAO.swift:101)
24 [APP]                    0x26699c ProjectViewModel.delete() + 4300515740 (<compiler-generated>:4300515740)
26 SwiftUI                        0x72b3d4 OUTLINED_FUNCTION_1 + 3372
27 SwiftUI                        0xf3e740 OUTLINED_FUNCTION_4 + 11076
28 SwiftUI                        0xe6010 OUTLINED_FUNCTION_242 + 6312
29 SwiftUI                        0x3bbe4 OUTLINED_FUNCTION_97 + 1476
30 SwiftUI                        0xe6010 OUTLINED_FUNCTION_242 + 6312
31 SwiftUI                        0x9d6f10 OUTLINED_FUNCTION_15 + 868
32 SwiftUI                        0x19bc4 OUTLINED_FUNCTION_28 + 480
33 SwiftUI                        0x15848 OUTLINED_FUNCTION_103 + 440
34 SwiftUI                        0x1ff80 OUTLINED_FUNCTION_757 + 3344
35 SwiftUI                        0x18e3c OUTLINED_FUNCTION_148 + 272
36 SwiftUI                        0x1ba08 OUTLINED_FUNCTION_122 + 200
37 UIKitCore                      0xb8a10 -[UIGestureRecognizer _componentsEnded:withEvent:] + 184
38 UIKitCore                      0xb5558 -[UITouchesEvent _sendEventToGestureRecognizer:] + 464
39 UIKitCore                      0x9ba3a4 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 172
40 UIKitCore                      0xf6df4 -[UIGestureEnvironment _updateForEvent:window:] + 188
41 UIKitCore                      0xfb760 -[UIWindow sendEvent:] + 3268
42 UIKitCore                      0xfaa20 -[UIApplication sendEvent:] + 676
43 UIKit                          0x2d800 -[UIApplicationAccessibility sendEvent:] + 96
44 UIKitCore                      0xfa0d8 __dispatchPreprocessedEventFromEventQueue + 7084
45 UIKitCore                      0x141e00 __processEventQueue + 5632
46 UIKitCore                      0xd9f820 updateCycleEntry + 168
47 UIKitCore                      0x6525b0 _UIUpdateSequenceRun + 84
48 UIKitCore                      0xca1310 schedulerStepScheduledMainSection + 172
49 UIKitCore                      0xca04dc runloopSourceCallback + 92
50 CoreFoundation                 0xd5f24 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
51 CoreFoundation                 0xe22fc __CFRunLoopDoSource0 + 176
52 CoreFoundation                 0x661c0 __CFRunLoopDoSources0 + 244
53 CoreFoundation                 0x7bb7c __CFRunLoopRun + 836
54 CoreFoundation                 0x80eb0 CFRunLoopRunSpecific + 612
55 GraphicsServices               0x1368 GSEventRunModal + 164
56 UIKitCore                      0x3a1668 -[UIApplication _run] + 888
57 UIKitCore                      0x3a12cc UIApplicationMain + 340
58 libswiftUIKit.dylib            0x35308 UIApplicationMain(_:_:_:_:) + 104
60 ???                            0x1aa384960 (Missing)

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0xda8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x13a1c mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x13c5c mach_msg_overwrite + 388
3  libsystem_kernel.dylib         0x12ec mach_msg + 24
4  CoreFoundation                 0x7aac4 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x7bd08 __CFRunLoopRun + 1232
6  CoreFoundation                 0x80eb0 CFRunLoopRunSpecific + 612
7  Foundation                     0x42054 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Foundation                     0x41f3c -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9  UIKitCore                      0x4d66a4 -[UIEventFetcher threadMain] + 436
10 Foundation                     0x5b518 __NSThread__start__ + 716
11 libsystem_pthread.dylib        0x16cc _pthread_start + 148
12 libsystem_pthread.dylib        0xba4 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0xda8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x13a1c mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x13c5c mach_msg_overwrite + 388
3  libsystem_kernel.dylib         0x12ec mach_msg + 24
4  [APP]                    0xaa2310 FIRCLSMachExceptionServer + 192 (FIRCLSMachException.c:192)
5  libsystem_pthread.dylib        0x16cc _pthread_start + 148
6  libsystem_pthread.dylib        0xba4 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x12b0 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe44 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb98 start_wqthread + 8

Realm notification listener
0  libsystem_kernel.dylib         0x26e0 kevent + 8
1  [APP]                    0x6fb454 realm::_impl::ExternalCommitHelper::listen() + 220 (external_commit_helper.cpp:220)
2  [APP]                    0x6fb634 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0>>(void*) + 191 (tuple:191)
3  libsystem_pthread.dylib        0x16cc _pthread_start + 148
4  libsystem_pthread.dylib        0xba4 thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0xda8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x13a1c mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x13c5c mach_msg_overwrite + 388
3  libsystem_kernel.dylib         0x12ec mach_msg + 24
4  CoreFoundation                 0x7aac4 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x7bd08 __CFRunLoopRun + 1232
6  CoreFoundation                 0x80eb0 CFRunLoopRunSpecific + 612
7  CFNetwork                      0x257ff0 _CFURLStorageSessionDisableCache + 61088
8  Foundation                     0x5b518 __NSThread__start__ + 716
9  libsystem_pthread.dylib        0x16cc _pthread_start + 148
10 libsystem_pthread.dylib        0xba4 thread_start + 8

com.squareup.SocketRocket.NetworkThread
0  libsystem_kernel.dylib         0xda8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x13a1c mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x13c5c mach_msg_overwrite + 388
3  libsystem_kernel.dylib         0x12ec mach_msg + 24
4  CoreFoundation                 0x7aac4 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x7bd08 __CFRunLoopRun + 1232
6  CoreFoundation                 0x80eb0 CFRunLoopRunSpecific + 612
7  Foundation                     0x42054 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Intercom                       0x89f94 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 70320
9  Foundation                     0x5b518 __NSThread__start__ + 716
10 libsystem_pthread.dylib        0x16cc _pthread_start + 148
11 libsystem_pthread.dylib        0xba4 thread_start + 8

com.apple.CFSocket.private
0  libsystem_kernel.dylib         0x190c select$DARWIN_EXTSN + 8
1  libsystem_kernel.dylib         0x190c __select + 8
2  CoreFoundation                 0xcb694 __CFSocketManager + 636
3  libsystem_pthread.dylib        0x16cc _pthread_start + 148
4  libsystem_pthread.dylib        0xba4 thread_start + 8

com.apple.SwiftUI.AsyncRenderer
0  libsystem_kernel.dylib         0xda8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x13a1c mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x13c5c mach_msg_overwrite + 388
3  libsystem_kernel.dylib         0x12ec mach_msg + 24
4  CoreFoundation                 0x7aac4 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x7bd08 __CFRunLoopRun + 1232
6  CoreFoundation                 0x80eb0 CFRunLoopRunSpecific + 612
7  Foundation                     0x42054 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Foundation                     0x41ee8 -[NSRunLoop(NSRunLoop) run] + 64
9  SwiftUI                        0xa7458 OUTLINED_FUNCTION_581 + 864
10 SwiftUI                        0xa55b8 __swift_memcpy40_8 + 2160
11 Foundation                     0x5b518 __NSThread__start__ + 716
12 libsystem_pthread.dylib        0x16cc _pthread_start + 148
13 libsystem_pthread.dylib        0xba4 thread_start + 8

Steps & Code to Reproduce

According to the logs, this happens when the user tries to update or delete a specific Realm Object.
The involved ObjectA has a small number of properties it self, but it includes a List of embedded objects List<[ChildObjectA]> (Embedded), which more often then not, it's a list with 1 element. This specific ChildObjectA has a link with an ObjectB (not embedded) that has further links with List of other objects. When updating ObjectA, in this specific case, we are actually creating a new instance of it and pass the old primary key value. So instead of modifying one or more properties, we call realm.add but with the update policy set to override all the properties, even if not changed.

From the stack trace, it seems we are hitting a Realm assert (REALM_ASSERT_3 called in ArrayBacklink::remove), but we were not able to reproduce nor to understand in what situations is this happening.

I am unable to share code, but I can provide more information on the Objects involved, if needed, such as a more detailed data structure and the manipulation.

@alexeyfof
Copy link

Hi Dan!
Thank you for very detailed explanation.
According to our logs we have exactly the same issue.

@jedelbo
Copy link
Contributor

jedelbo commented May 16, 2023

The issue is that while removing an object we are trying to remove the backlinks pointing back to the deleted object. We do that by following the forward links and then search for the key of the deleted object. If that key is not found an assertion will be triggered. It is a sign that some inconsistency is found (a forward link with no matching backward link). We might consider just ignoring the inconsistency silently as that would allow you to still use the realm file.

@jedelbo
Copy link
Contributor

jedelbo commented May 16, 2023

@bodnar-dan Can you disclose what your schema looks like? How are the properties on the object that you are removing defined?
Would it be possible to get hold of the users realm file?

@jedelbo
Copy link
Contributor

jedelbo commented May 26, 2023

@bodnar-dan Although we have closed this, I think there is more to this than what our fix fixes. So I would very much like to hear if the Dictionary you use is a Dictionary of embedded objects?
@alexeyfof perhaps you can also share that information.

@jedelbo jedelbo reopened this May 26, 2023
@jedelbo
Copy link
Contributor

jedelbo commented May 26, 2023

Are any of you using sync?

@kiburtse
Copy link
Contributor

@bodnar-dan @alexeyfof could you provide some additional information? Schema definition and code samples would be great to see!
As for #6638 it should be now released with Realm Swift 10.40.0 Did it help your case?

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Jun 15, 2023
@kiburtse kiburtse added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Jun 15, 2023
@github-actions
Copy link
Contributor

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@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.
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community Waiting-For-Reporter Waiting for more information from the reporter before we can proceed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants