Page MenuHomePhabricator

Fix performBatchUpdates() crash
Open, LowPublicBUG REPORT

Description

Have not seen this in the wild but we are seeing this crash much more often in 6.6.0 vs. 6.5.1. This is similar to the background crash that we already have logged, but it is not triggered on pauseApp so this is probably happening in the foreground.

Last Exception Backtrace:
0   CoreFoundation                	0x1af047794 __exceptionPreprocess + 224 (NSException.m:199)
1   libobjc.A.dylib               	0x1aed69bcc objc_exception_throw + 56 (objc-exception.mm:565)
2   CoreFoundation                	0x1aef4a82c +[NSException raise:format:arguments:] + 96 (NSException.m:146)
3   Foundation                    	0x1af38216c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 128 (NSException.m:231)
4   UIKitCore                     	0x1b2941880 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 13652 (UICollectionView.m:6819)
5   UIKitCore                     	0x1b2948eb0 -[UICollectionView _endUpdatesWithInvalidationContext:tentativelyForReordering:animator:] + 92 (UICollectionView.m:7991)
6   UIKitCore                     	0x1b29491fc -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:] + 408 (UICollectionView.m:8040)
7   UIKitCore                     	0x1b2949044 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 96 (UICollectionView.m:8013)
8   UIKitCore                     	0x1b2948fc8 -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 84 (UICollectionView.m:8008)
9   UIKitCore                     	0x1b2948f04 -[UICollectionView performBatchUpdates:completion:] + 64 (UICollectionView.m:7997)
10  Wikipedia                     	0x102b832b8 CollectionViewUpdater.performBatchUpdates() + 372 (CollectionViewUpdater.swift:165)
11  Wikipedia                     	0x102b88780 partial apply for closure #2 in CollectionViewUpdater.controllerDidChangeContent(_:) + 20 (CollectionViewUpdater.swift:159)
12  Wikipedia                     	0x102c929f8 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
13  UIKitCore                     	0x1b3596880 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 540 (UIView.m:14246)
14  UIKitCore                     	0x1b3596d00 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:] + 172 (UIView.m:14291)
15  Wikipedia                     	0x102b88658 specialized CollectionViewUpdater.controllerDidChangeContent(_:) + 2780 (CollectionViewUpdater.swift:0)
16  Wikipedia                     	0x102b83128 @objc CollectionViewUpdater.controllerDidChangeContent(_:) + 48 (<compiler-generated>:0)
17  CoreData                      	0x1b3acb130 __82-[NSFetchedResultsController(PrivateMethods) _core_managedObjectContextDidChange:]_block_invoke + 5860 (NSFetchedResultsController.m:2155)
18  CoreData                      	0x1b3a8a754 developerSubmittedBlockToNSManagedObjectContextPerform + 156 (NSManagedObjectContext.m:3774)
19  CoreData                      	0x1b395aeb0 -[NSManagedObjectContext performBlockAndWait:] + 208 (NSManagedObjectContext.m:3885)
20  CoreData                      	0x1b3964320 -[NSFetchedResultsController(PrivateMethods) _core_managedObjectContextDidChange:] + 108 (NSFetchedResultsController.m:2187)
21  CoreFoundation                	0x1aefa3644 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:787)
22  CoreFoundation                	0x1aefa368c ___CFXRegistrationPost1_block_invoke + 64 (CFNotificationCenter.c:175)
23  CoreFoundation                	0x1aefa29e4 _CFXRegistrationPost1 + 368 (CFNotificationCenter.c:198)
24  CoreFoundation                	0x1aefa26bc ___CFXNotificationPost_block_invoke + 88 (CFNotificationCenter.c:1371)
25  CoreFoundation                	0x1aef1f414 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1412 (CFXNotificationRegistrarOld.m:168)
26  CoreFoundation                	0x1aefa201c _CFXNotificationPost + 1236 (CFNotificationCenter.c:1359)
27  Foundation                    	0x1af301974 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60 (NSNotification.m:576)
28  CoreData                      	0x1b396b350 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postContextDidMergeChangesNotificationWithUserInfo:] + 716 (NSManagedObjectContext.m:8214)
29  CoreData                      	0x1b39641d0 -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:deletions:updates:refreshes:deferrals:wasMerge:] + 1376 (NSManagedObjectContext.m:7691)
30  CoreData                      	0x1b396e624 -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList] + 192 (NSManagedObjectContext.m:7246)
31  CoreData                      	0x1b3963094 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 100 (NSManagedObjectContext.m:7324)
32  CoreData                      	0x1b396a8cc -[NSManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:] + 4676 (NSManagedObjectContext.m:3514)
33  CoreData                      	0x1b396ac38 -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:] + 472 (NSManagedObjectContext.m:3542)
34  CoreData                      	0x1b3a8a754 developerSubmittedBlockToNSManagedObjectContextPerform + 156 (NSManagedObjectContext.m:3774)
35  libdispatch.dylib             	0x1aed0d524 _dispatch_client_callout + 16 (object.m:495)
36  libdispatch.dylib             	0x1aecbf5b4 _dispatch_main_queue_callback_4CF$VARIANT$mp + 904 (inline_internal.h:2484)
37  CoreFoundation                	0x1aefc57fc __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1749)
38  CoreFoundation                	0x1aefc06d0 __CFRunLoopRun + 1724 (CFRunLoop.c:3069)
39  CoreFoundation                	0x1aefbfce8 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3192)
40  GraphicsServices              	0x1b910a38c GSEventRunModal + 160 (GSEvent.c:2246)
41  UIKitCore                     	0x1b30ee444 UIApplicationMain + 1932 (UIApplication.m:4823)
42  Wikipedia                     	0x102b13514 main + 132 (main.m:47)
43  libdyld.dylib                 	0x1aee478f0 start + 4

Related Objects

Event Timeline

We've confirmed this happens from the Explore feed, but still not sure why it's so much more prevalent. One thought is to remove the spring animation and see if that improves anything.

I did some additional investigation and it looks like the crash occurs even if performBatchUpdates is called outside of the animation block in CollectionViewUpdater.swift. So that probably rules out the animation block being an issue and points towards an invalid collection view update.

Since the crashes are only happening on iOS 13 (so far) - it seemed worth investigating the new mechanism for updating the UICollectionView introduced in iOS 13 that @Dmantena mentioned. I created a branch to investigate that approach. It mostly works, but there are bugs around the edges. Due to the impact of that fix and given the crash level has subsided, I don't think it's worth pursuing that at the moment, but leaving it here for if/when this work is revisited.

LGoto triaged this task as Medium priority.Jun 1 2020, 6:48 PM
LGoto moved this task from Needs Triage to Bug Backlog on the Wikipedia-iOS-App-Backlog board.
LGoto lowered the priority of this task from Medium to Low.Jul 14 2020, 6:50 PM

Here's some crash counts I've talleyed from organizer (last 2 weeks, so there's definitely a "first launch" bias here):

Current crash device count in 6.8.0: 122
Current crash device count in 6.7.4: 524