wordpress-mobile / WordPress-iOS

WordPress for iOS - Official repository
http://ios.wordpress.org/
GNU General Public License v2.0
3.66k stars 1.11k forks source link

CoreData crash: EXC_BAD_ACCESS _undoDeletions: > _undoInsertions: > _undoUpdates: #20859

Open guarani opened 1 year ago

guarani commented 1 year ago

Description

CoreData-related crash. Logs indicate crashes happening after the app was launched by a remote notification.

EXC_BAD_ACCESS
_undoDeletions: > _undoInsertions: > _undoUpdates: > countByEnumeratingWithState:objects:count: >
KERN_INVALID_ADDRESS at 0x794d59020.
2023-06-02 10:47:56:952 Launch options: [__C.UIApplicationLaunchOptionsKey(_rawValue: UIApplicationLaunchOptionsRemoteNotificationKey):

Sentry

Sentry Urls: https://a8c.sentry.io/issues/3138940981/events/c899bbd8ae6043199fab1b5b1c93b0b8/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/9a8f113549e9493f813c50e7d5cfa953/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/7e0d0031cd3e418dbbef38ade6cdf123/?project=5716771 User Count: 1424 Count: 2669 First Release: 19.4.1.0 First Seen: 2022-03-29T12:49:14Z Last Seen: 2023-06-13T15:50:01Z 24 Hours: 8 30 Days: 331 LogID: 362D1E43-3EDF-4F1A-A98C-EB01A831415F

Other issues:

There're issues grouped together with this event, created separate tickets:

guarani commented 1 year ago

Added priority Urgent on GitHub board since this Sentry issue JETPACK-IOS-2X has three events that could correspond to the crash (or crashes) reported and being discussed in https://a8c.slack.com/archives/C05CANZ2B6F:

staskus commented 1 year ago

This Sentry report contains multiple core data and/or memory-related crashes. They are grouped together since 19.4. I focus on the issues that appear in the most recent versions >=22.2.

Core Data crashes that have logs containing Launch options: [__C.UIApplicationLaunchOptionsKey(_rawValue: UIApplicationLaunchOptionsRemoteNotificationKey)

EXC_BAD_ACCESS
_undoDeletions: > _undoInsertions: > _undoUpdates: > countByEnumeratingWithState:objects:count: >
KERN_INVALID_ADDRESS at 0x794d59020.

These crashes look to be happening after app is launched by the remote notification UIApplicationLaunchOptionsRemoteNotificationKey and then app being loaded. These are CoreData related crashes.

It could be related to the:

Other CoreData related EXC_BAD_ACCESS: [C2.1.1:3] > retain >

KERN_INVALID_ADDRESS at 0x312e312e324368.

https://a8c.sentry.io/issues/3138940981/events/b9ec6bdd393c49c88dbbdf32ebc21c17/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/c5700b7b43864e35b6e0157211bfa014/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/7afecbcced88477b8b67a401a31a76b1/?project=5716771

Application Specific Information:
[C2.1.1:3] > retain >
KERN_INVALID_ADDRESS at 0x312e312e324368.

Thread 0 Crashed:
0   libobjc.A.dylib                 0x332c86820         objc_msgSend
1   CoreData                        0x34f9a1834         -[NSManagedObjectContext _refaultObject:globalID:boolean:]
2   CoreData                        0x34f962118         -[NSManagedObjectContext _mergeRefreshObject:mergeChanges:withPersistentSnapshot:]
3   CoreData                        0x34f97a36c         -[NSManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:]
4   CoreData                        0x34f98383c         -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:]
5   CoreData                        0x34f982b68         developerSubmittedBlockToNSManagedObjectContextPerform

Media upload KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED

Opened GitHub issue: https://github.com/wordpress-mobile/WordPress-iOS/issues/20882

https://a8c.sentry.io/issues/3138940981/events/7b69e5ef94aa4e77b71fd6b29af1825b/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/2379e20947804bda80962e97177426f3/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/451fdac6b0bf4a66a1ed3b9ba8abbf9a/?project=5716771

The logs indicate that the last action was Media upload in the PostCoordinator:

2023-06-12 11:17:48:244 Post Coordinator -> Media state: Progress: 0.9982957538795946
2023-06-12 11:17:48:371 Post Coordinator -> Media state: Progress: 0.9999999756470167
2023-06-12 11:17:55:216 πŸ”΅ Tracked: media_service_upload_successfu 2023-06-12 11:17:55:234 Post Coordinator -> Media state: Progress: 1.0 

A crash with such a trace could indicate memory issues when observing objects without deinitializing the observer.

Theoretically, could be related to other issues that involve PostCoordinator but I haven't indicated a direct relationship between these crashes:

There're some other KVO-related crashes, could be related:

Keyboard presentation EXC_BAD_ACCESS: XTUM > Attempted to dereference garbage pointer 0x92e02a80, EXC_BAD_ACCESS: Exception 1, Code 1, Subcode 15487970336 > KERN_INVALID_ADDRESS at 0x39b27ac20

Opened GitHub issue: https://github.com/wordpress-mobile/WordPress-iOS/issues/20883

https://a8c.sentry.io/issues/3138940981/events/7f69f79b3aef4548b80b8699c3992f90/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/f1417884cbe7422c8c2524ea83a9d065/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/bb475ed106b443179eb0ea1a0f371d8c/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/36849bb85d244a649c10a5356daaa3fb/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/08f6e9d542d745619d9645c3267eb583/?project=5716771 https://a8c.sentry.io/issues/3138940981/events/47246d1871b84e978abae03aecce4984/?project=5716771

The distinct feature looks to be a keyboard event:

{
action: UIKeyboardDidShowNotification
}

The variety of events

image
staskus commented 1 year ago

Update

EXC_BAD_ACCESS _undoDeletions: > _undoInsertions: > _undoUpdates: > countByEnumeratingWithState:objects:count: > KERN_INVALID_ADDRESS at 0x794d59020.

I didn't reproduce the issue.

This crash looks to be happening when the app is in the background state:

2023-06-07 14:17:43:627 Launching Jetpack for iOS 22.4 (22.4.0.2)
2023-06-07 14:17:43:629 Launch options: [__C.UIApplicationLaunchOptionsKey(_rawValue: UIApplicationLaunchOptionsRemoteNotificationKey):..
<...>
2023-06-07 14:17:43:834 didFinishLaunchingWithOptions state: UIApplicationState(rawValue: 2)
2023-06-07 14:17:43:864 <WordPress.WordPressAppDelegate: 0x281c74270> application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
2023-06-07 14:17:43:873 πŸ”΅ Tracked: push_notification_received
<...>
2023-06-07 14:17:43:881 Running Notifications Background Fetch...
<...>
2023-06-07 14:17:43:966 πŸ”΅ Tracked: blaze_entry_point_displayed <source: dashboard_card>
2023-06-07 14:17:44:120 πŸ”΅ Tracked: my_site_dashboard_shown <>
<...>
2023-06-07 14:17:44:905 Finished Notifications Background Fetch!
<...>
2023-06-07 14:17:45:833 πŸ”΅ Tracked: blogging_prompts_my_site_card_viewed <tab_source: dashboard>
  1. The application is launched by remote notification
  2. UIApplicationState(rawValue: 2) is for the background state and push_notification_received also indicates that the app is in the background
  3. willFinishLaunchingWithOptions and didFinishLaunchingWithOptions runs through the usual app launch and load the initial views. That's why my_site_dashboard_shown or blogging_prompts_my_site_card_viewed are tracked, even though users don't see it
  4. Finished Notifications Background Fetch! and blogging_prompts_my_site_card_viewed are the last ones before in the crash logs

Previous logs

Previous logs have shown the exactly same behavior of the app, the only difference is applicationWillTerminate indicated when Finished Notifications Background Fetch! is done:

2023-06-07 13:56:55:520 didFinishLaunchingWithOptions state: UIApplicationState(rawValue: 2)
2023-06-07 13:56:55:710 πŸ”΅ Tracked: push_notification_received
2023-06-07 13:56:55:715 Running Notifications Background Fetch...
2023-06-07 13:56:55:730 πŸ”΅ Tracked: my_site_dashboard_shown <>
2023-06-07 13:56:56:538 Finished Notifications Background Fetch!
2023-06-07 13:56:56:538 <WordPress.WordPressAppDelegate: 0x281428340> applicationWillTerminate(_:)

Conclusion

If these crashes are happening in the background, they are not visible to users and don't stop them in any of the flows. They are likely not the ones actively reported by users. The app crashes with CoreData issues in the background rather than being terminated by the system.

For now, we should improve CoreData issue logging, fix other reproducible CoreData issues, and address the usage of CoreData while observing if this crash continues to happen or if we manage to locate the root cause.

cc: @guarani

guarani commented 1 year ago

Thanks for the analysis, @staskus!

3. willFinishLaunchingWithOptions and didFinishLaunchingWithOptions runs through the usual app launch and load the initial views. That's why my_site_dashboard_shown or blogging_prompts_my_site_card_viewed are tracked, even though users don't see it

On a side note: I wonder if we're there's UI code in here that could be put behind an if-statement to only be executed when the launch option isn't a background process. Either way, there's no evidence that this is related to the crash.

If these crashes are happening in the background, they are not visible to users and don't stop them in any of the flows. They are likely not the ones actively reported by users. The app crashes with CoreData issues in the background rather than being terminated by the system.

Agreed

For now, we should improve CoreData issue logging, fix other reproducible CoreData issues, and address the usage of CoreData while observing if this crash continues to happen or if we manage to locate the root cause.

Good thoughts

staskus commented 1 year ago

There has been a decreasing occurrence of these issues by version:

136 occurrences on 22.3 101 occurrences on 22.4 35 occurrences on 22.5 28 occurrences on 22.6 3 occurrences on 22.7

image

Given this Sentry report's many issues, we'll continue observing the trends.

staskus commented 1 year ago

5 occurrences on 22.8.

Given the limited number of events for 2 releases in a row I'm removing it from monitoring. Given this Sentry report was a collection of different issues, this ticket needs to be reassessed.

sentry-io[bot] commented 1 year ago

Sentry issue: JETPACK-IOS-FAE

fluiddot commented 9 months ago

Following similar results as shared in https://github.com/wordpress-mobile/WordPress-iOS/issues/20859#issuecomment-1647834247, this crash has decreased over time. For the past 90 days (September and November 2023), we only received 48 events. For the current production version 23.6 (23.7 was released hours ago), we only received 2 events.

Considering the above, I'd like to propose lowering its priority, especially in relation to tackling it in maintenance efforts. cc @tiagomar