I have been spending the last several weeks implementing NSPersistentCloudKitContainer in my app, and it is most of the way there. Unfortunately, I keep running into an issue where after several days of successful syncing between devices, each device begins to crash after about a minute of use, repeatedly.
The crash report points to a SQL thread doing things with the CoreData and CloudKit frameworks — none of my code whatsoever. It is the typical “CPU: 48 seconds cpu time over 58 seconds (82% cpu average), exceeding limit of 80% cpu over 60 seconds” issue. If I run the devices hooked up to Xcode and debug, I see the thread spin up and the log shows it chugging through changed CKRecords it needs to import, just like normal. If I leave the devices hooked up to Xcode, they eventually make it through this huge job and the devices become usable again.
Once one device is in this state, the problem also occurs on new devices trying to download from the cloud for the first time.
I’ve attached a screenshot of the stacktrace of that thread in Instruments. I haven’t had any luck finding other people mentioning the system killing their app during a sync, so I’m kind of at a loss for what to do. It seems like the issue is occurring in a job that the NSPersistentCloudKitContainer is managing on my behalf and I haven’t been able to figure out a way to configure a timeout or anything.
Has anyone experienced this? I’m not sure what to do if the chunks that NSPersistentCloudKitContainer breaks up the import into are too large for the device to work through before the system kills the app. I’d appreciate any ideas or insights. Please let me know if any other information would be helpful.
Thanks!
I still have not figured out what is causing this. Am I really the only person getting cpu_usage_fatal crashes caused by CoreData/CloudKit syncs?
OK, commenting on your thread as I have the same issue (which you've found). Let's hope Apple is able to track down what's going on here. Only started with iOS15 beta 4 from my testing. https://developer.apple.com/forums/thread/687877
This seemed to coincide with other changes to NSPersistenCloudkitContainer's console outputs when syncing since beta 4. Something big has been changed behind the scenes I think and it's very much 'beta' again.