App getting killed by iOS while NSPersistentCloudKitContainer syncs

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.

Replies

I'm facing a the same problem.

In my case I'm collecting data in background mode. If internet connection gets lost, large amount of data might be sync when the device gets back on the internet. If data collection is still active, the background mode seems to keep NSPersistentCloudKitContainer alive resulting in the iCloud sync not being terminated and the app getting killed due to high CPU pressure.

What framework are you using? I'm using SwiftUI. I'm also still looking for a solution.

  • I've since submitted this as FB9489988

  • I've also cross referenced your Feedback ID in mine. My Feedback ID for this is: FB9412346 (is there a way to view someone else's feedback?)

  • I'm seeing this with UIKit but I think it's a NSPersistentCloudkitContainer issue so will be unrelated to the UI framework.

Add a Comment

Have you received any update from Apple on this? They have not replied to my Feedback report at all - not even acknowledged the receipt of my test data, or if it might even be something I’ve done wrong. Nothing.

We’re about a month away from release and this is going to break my app if not fixed - which has been working fine for the past 2 years using NSPersistentCloudKitContainer. I suspect there will be a lot of developers & users that will be caught off-guard if it’s released to the public as it’s only a ‘visible’ problem for those of us with slightly complex Core Data models.

My app is a medical record keeping app and my users are going to be extremely angry when it fails to sync after they upgrade to iOS15 if this isn’t fixed.

In my line of work (I’m an MD) this poor (or no) communication would see me sued by my patients (and quite rightly too) - people just need to know something is being done.

Something fundamentally changed with NSPersistentCloudKitContainer from beta 4 and this was obvious when you looked at the formatting of the console output when a sync did occur. It was totally different suddenly - it was the first thing I noticed. The second thing I noticed was that it didn’t work…

This is the first time, since I returned to Apple in 2004, that I feel really disappointed in them. Sigh.

  • Other than the response from a Frameworks Engineer in this thread just a few minutes after your post, no I hadn’t heard anything since 8/12 when Apple responded to my feedback asking for store files, like they asked you.

    After the problem wasn’t fixed as of beta 8, I started working on my own sync engine that writes backup files to iCloud Drive via the UbuiquityContainer APIs. I’m doing everything I can to have it done by the iOS 15 launch date but if it doesn’t seem like I’m going to and this crash still isn’t fixed in the GM I’m just going to submit an update that disables sync in 15 until my sync engine is ready for primetime. It’s a crummy solution but it doesn’t seem like I have another option.

  • I wouldn't even know how to do that - I'm not that advanced!! :-D The main question I want answered is this: If it is fixed at some point, will all the changes since the last successful sync (ie. from iOS 14) sync properly or will the user's entire iCloud container need resetting?

Add a Comment

Please file a feedback report and include your instruments trace file. A link to this thread would also be helpful.

  • I submitted a feedback for this several weeks ago and have provided sysdiagnoses and exports of the store files: FB9489988

  • Me too and have heard nothing back from Apple in my feedback, despite providing some of the information they needed and asking how to provide the remainder, etc. FB9412346

  • Still broken in 15.1 beta 2...

Add a Comment

These aren't all the same issue. FB9489988 here is due to additional restrictions being applied by adopting the background music playing entitlement. This should be fixed in the next iOS 15.1 beta, which I think will be beta 3.

Same here. The problem is from iOS 15 beta 4 to now(iOS 16 beta 6). Sync in iOS 14 is so nice.