App crashes when CoreData item is deleted from SwiftUI List

Originator:iltercengiz1
Number:rdar://FB8545866 Date Originated:27/08/2020
Status:Open Resolved:
Product:SwiftUI Product Version:iOS 14 and above
Classification:Bug Reproducible:Always
 
Problem:
Application crashes when a row is deleted in a SwiftUI List populated with NSManagedObject instances.
Example project: https://www.icloud.com/iclouddrive/0HttLnRotPLk2C3RmSXZ7NDXw#CoreData_SwiftUI

Steps to reproduce:
In the example project attached, run the app in one of the simulators, tap “Add” in the top right corner to add a few items, swipe a row to delete it.

What is expected:
Row to be deleted and CoreData context to be saved.

What happens:
Application crashes with the following log:

Simultaneous accesses to 0x7fc8e5e29fb8, but modification requires exclusive access.
Previous access (a modification) started at SwiftUI`closure #2 in ListCoreCoordinator.tableView(_:commit:forRowAt:) + 53 (0x10af83e05).
Current access (a read) started at:
0    libswiftCore.dylib                 0x000000010e1b6890 swift_beginAccess + 568
1    SwiftUI                            0x000000010af7fc50 ListCoreCoordinator.dataSource.getter + 50
2    SwiftUI                            0x000000010af80720 ListCoreCoordinator.updateUITableView(_:to:transaction:) + 608
3    SwiftUI                            0x000000010af7f510 ListRepresentable.updateUIView(_:context:) + 911
4    SwiftUI                            0x000000010b3d7860 PlatformViewRepresentableAdaptor.updateViewProvider(_:context:) + 263
5    SwiftUI                            0x000000010b0255a0 closure #1 in closure #1 in closure #4 in closure #1 in PlatformViewChild.updateValue() + 229
6    SwiftUI                            0x000000010b0254f0 closure #1 in closure #4 in closure #1 in PlatformViewChild.updateValue() + 114
7    SwiftUI                            0x000000010b2cd480 ViewRendererHost.performExternalUpdate(_:) + 186
8    SwiftUI                            0x000000010b025480 closure #4 in closure #1 in PlatformViewChild.updateValue() + 73
9    SwiftUI                            0x000000010b023ec0 closure #1 in PlatformViewChild.updateValue() + 2079
10   SwiftUI                            0x000000010b023920 PlatformViewChild.updateValue() + 650
11   SwiftUI                            0x000000010ad50820 partial apply for implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>(_:) + 26
12   AttributeGraph                     0x0000000111669b0a AG::Graph::UpdateStack::update() + 505
13   AttributeGraph                     0x000000011166a04a AG::Graph::update_attribute(AG::data::ptr<AG::Node>, bool) + 335
14   AttributeGraph                     0x0000000111671f38 AG::Subgraph::update(unsigned int) + 781
15   SwiftUI                            0x000000010b367b20 GraphHost.runTransaction() + 186
16   SwiftUI                            0x000000010b36b6a0 GraphHost.runTransaction(_:) + 79
17   SwiftUI                            0x000000010b36a140 GraphHost.flushTransactions() + 211
18   SwiftUI                            0x000000010b3692b0 specialized GraphHost.asyncTransaction<A>(_:mutation:style:) + 484
19   SwiftUI                            0x000000010af49de0 AttributeInvalidatingSubscriber.invalidateAttribute() + 236
20   SwiftUI                            0x000000010af49d60 AttributeInvalidatingSubscriber.receive(_:) + 105
21   SwiftUI                            0x000000010af4a3f0 protocol witness for Subscriber.receive(_:) in conformance AttributeInvalidatingSubscriber<A> + 16
22   SwiftUI                            0x000000010b0d7af0 SubscriptionLifetime.Connection.receive(_:) + 89
23   Combine                            0x0000000111b3f5f0 ObservableObjectPublisher.Inner.send() + 122
24   Combine                            0x0000000111b3ebe0 ObservableObjectPublisher.send() + 801
25   libswiftCoreData.dylib             0x000000010e5aa880 @objc NSManagedObject._willChange_Swift_Trampoline() + 114
26   CoreData                           0x000000010a40956f -[NSManagedObjectContext _postObjectsDidChangeNotificationWithUserInfo:] + 773
27   CoreData                           0x000000010a41828f -[NSManagedObjectContext _createAndPostChangeNotification:deletions:updates:refreshes:deferrals:wasMerge:] + 1825
28   CoreData                           0x000000010a40a32d -[NSManagedObjectContext _processRecentChanges:] + 1041
29   CoreData                           0x000000010a36e9bd -[NSManagedObjectContext save:] + 356
30   CDSUI                              0x0000000109a9bcc0 closure #2 in closure #1 in ListView.body.getter + 439
31   SwiftUI                            0x000000010ab318a0 partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed IndexSet) -> () + 17
32   SwiftUI                            0x000000010b142a10 partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed IndexSet) -> (@out ()) + 17
33   SwiftUI                            0x000000010ab31a30 DeleteInteraction.delete() + 125
34   SwiftUI                            0x000000010aee2e20 SystemListDataSource.deleteCell(forRowAt:) + 64
35   SwiftUI                            0x000000010b09e230 ShadowListDataSource.commitUpdates() + 963
36   SwiftUI                            0x000000010af83dd0 closure #2 in ListCoreCoordinator.tableView(_:commit:forRowAt:) + 76
37   SwiftUI                            0x000000010af83ab0 ListCoreCoordinator.tableView(_:commit:forRowAt:) + 455
38   SwiftUI                            0x000000010af83e30 @objc ListCoreCoordinator.tableView(_:commit:forRowAt:) + 131
39   UIKitCore                          0x00000001146a0891 -[UITableView _animateDeletionOfRowAtIndexPath:] + 188
40   UIKitCore                          0x00000001146a901a __82-[UITableView _contextualActionForDeletingRowAtIndexPath:usingPresentationValues:]_block_invoke + 60
41   UIKitCore                          0x00000001145f1b0b -[UIContextualAction executeHandlerWithView:completionHandler:] + 148
42   UIKitCore                          0x00000001145ff9f8 -[UISwipeOccurrence _executeLifecycleForPerformedAction:sourceView:completionHandler:] + 514
43   UIKitCore                          0x0000000114600047 -[UISwipeOccurrence _performSwipeAction:inPullView:swipeInfo:] + 621
44   UIKitCore                          0x0000000114601d6d -[UISwipeOccurrence swipeActionPullView:tappedAction:] + 92
45   UIKitCore                          0x0000000114609bae -[UISwipeActionPullView _tappedButton:] + 148
46   UIKitCore                          0x00000001144711dc -[UIApplication sendAction:to:from:forEvent:] + 83
47   UIKitCore                          0x0000000113d9ed49 -[UIControl sendAction:to:forEvent:] + 223
48   UIKitCore                          0x0000000113d9efff -[UIControl _sendActionsForEvents:withEvent:] + 332
49   UIKitCore                          0x0000000113d9d840 -[UIControl touchesEnded:withEvent:] + 500
50   UIKitCore                          0x0000000113f9d9fa _UIGestureEnvironmentUpdate + 8849
51   UIKitCore                          0x0000000113f9d207 -[UIGestureEnvironment _updateForEvent:window:] + 887
52   UIKitCore                          0x00000001144ae829 -[UIWindow sendEvent:] + 4752
53   UIKitCore                          0x000000011448927d -[UIApplication sendEvent:] + 633
54   UIKit                              0x0000000136b6dc99 -[UIApplicationAccessibility sendEvent:] + 85
55   UIKitCore                          0x00000001145163eb __processEventQueue + 13895
56   UIKitCore                          0x0000000114510360 __eventFetcherSourceCallback + 104
57   CoreFoundation                     0x000000010f732834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
58   CoreFoundation                     0x000000010f732689 __CFRunLoopDoSource0 + 180
59   CoreFoundation                     0x000000010f731b27 __CFRunLoopDoSources0 + 248
60   CoreFoundation                     0x000000010f72c089 __CFRunLoopRun + 878
61   CoreFoundation                     0x000000010f72b967 CFRunLoopRunSpecific + 567
62   GraphicsServices                   0x0000000111532d28 GSEventRunModal + 139
63   UIKitCore                          0x000000011446a8e3 -[UIApplication _run] + 912
64   UIKitCore                          0x000000011446fb1f UIApplicationMain + 101
65   libswiftUIKit.dylib                0x000000010ea0f750 UIApplicationMain(_:_:_:_:) + 98
66   CDSUI                              0x0000000109a98ff0 static UIApplicationDelegate.main() + 122
67   CDSUI                              0x0000000109a98fb0 static AppDelegate.$main() + 46
68   CDSUI                              0x0000000109a99090 main + 41
69   libdyld.dylib                      0x000000011022e414 start + 1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!