NSPersistentCloudKitContainer - Import failed because applying the accumulated changes hit an unhandled exception

When I use NSPersistentCloudKitContainer to sync data, I receive error Code=134421/134406 Import failed because applying the accumulated changes hit an unhandled exception.

iOS/iPadOS 15 beta 5 - iOS/iPadOS 15 beta 7(latest)

When this error appears, data can not be import/merged from iCloud. Delete app and reinstall is not working.

Same momd on macOS 12(Catalyst, with full data upgrated from macOS 11) works fine. Maybe a system bug?

Merge Policy:

context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
context.automaticallyMergesChangesFromParent = true

Console log here:

CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](1826): <NSCloudKitMirroringDelegate: 0x282f3c180> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringExportRequest: 0x2815d8180> B7974D4D-C5DA-413E-AE3B-072C88D38D47' due to error: Error Domain=NSCocoaErrorDomain Code=134421 "Import failed because applying the accumulated changes hit an unhandled exception." UserInfo={NSLocalizedFailureReason=Import failed because applying the accumulated changes hit an unhandled exception., NSUnderlyingException=*** NSAllocateMemoryPages(103626821) failed}
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _finishedRequest:withResult:](2713): Finished request: <NSCloudKitMirroringExportRequest: 0x2815d8180> B7974D4D-C5DA-413E-AE3B-072C88D38D47 with result: <NSCloudKitMirroringResult: 0x281b51060> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134406 "Request 'B7974D4D-C5DA-413E-AE3B-072C88D38D47' was aborted because the mirroring delegate never successfully initialized due to error: Error Domain=NSCocoaErrorDomain Code=134421 "Import failed because applying the accumulated changes hit an unhandled exception." UserInfo={NSLocalizedFailureReason=Import failed because applying the accumulated changes hit an unhandled exception., NSUnderlyingException=*** NSAllocateMemoryPages(103626821) failed}" UserInfo={NSLocalizedFailureReason=Request 'B7974D4D-C5DA-413E-AE3B-072C88D38D47' was aborted because the mirroring delegate never successfully initialized due to error: Error Domain=NSCocoaErrorDomain Code=134421 "Import failed because applying the accumulated changes hit an unhandled exception." UserInfo={NSLocalizedFailureReason=Import failed because applying the accumulated changes hit an unhandled exception., NSUnderlyingException=*** NSAllocateMemoryPages(103626821) failed}}

This won’t answer your question, sorry… but it might be related to the problem several of us are having with NSPersistentCloudKitContainer - it seemed to appear with beta 4 and is still present with beta 7. Something fundamental was modified in beta 4 and sure hope it’s fixed before release otherwise I’m in real trouble (from my users!).

See here for my thread on the issue.

Update: iOS 15 RC still has this problem.

With same data, simulator works fine, while device failed.

Memory issue caused by long string or something else?

it is not fixed on iPadOS/iOS 15.1 beta. 🥲🥲

A TSI is requested.

I do expect it improved in 15.1b2. Please file your own bug report and include a sysdiagnose, the app container with the database from the Xcode organizer, and if possible an Instruments sample with the memory tool.

Sorry for the late. Sample is uploaded. FB9659774. I known little about instrument, if anything is missing, please tell me.

iOS 15.2 beta

It's not solved yet. iOS 15.3 beta.

Still a problem in 15.4 beta too.

Update for anyone else with this issue. Here is the reply I have received from Framework engineers in response to bug report

We have additional information, the root cause of this issue is a large number of incoming images in the same import.  You can work around this by syncing your images with CloudKit directly via a CKRecord you own (instead of letting NSPersistentCloudKitContainer do it). We will continue to improve the performance of NSPersistentCloudKitContainer and followup again in this feedback report when the issue is resolved.

I have had multiple users of my app report these error codes, though I can't reproduce the problem. I'm hoping someone on the Core Data + CloudKit team can escalate this to the top of their priority list... I have users that can't access any of their data on a new device because the import fails over and over again. What do I tell them? Even if I could wrap my head around the suggested workaround of syncing images with CloudKit directly, it doesn't sound like that would help users whose existing databases simply will not sync. I have people staring at an empty tableview because nothing will appear and they think their data has been erased. That's a pretty significant problem and calls into question the reliability of Apple's syncing solutions.

In my data model, images are stored as separate entities specifically to avoid this situation, and yet here we are. Any cloud syncing solution should be able to handle a large number of images. I'd imagine most of my users have less than 100, and I even downscale them a bit! I don't mean to sound combative -- I'm sure the CloudKit team is diligently working through a large to-do list, but I would greatly appreciate an official response to this issue.

Please file a bug report with Apple using Feedback, if you haven't already done so.

Quote my report FB9859660. I am in the same situation as you, and feel as though I'm the only one! I too don't know what to say to my users, other than Apple have a bug and they are working on it, with no timescale for resolution. People are not happy!

It was working perfectly well in iOS14. Now it's not in iOS15. Instruments suggests to me that there is probably a memory leak in NSPersistentCloudKitContainer. Large spikes in Virtual Memory usage on all imports (even the small ones) but the small ones dont trigger a crash. The same (smallish) database in iOS14 uses 36MB of VM but in iOS15 uses 1.49GB for example!!

its not just images. I have a database that has no images and this happens. it does have a decent amount of records though - 100MB or so says the manage storage section of iCloud in the Settings app. iOS15.4.1

iOS 15.5 still broken

Memory issue seems fixed in iOS 15.5 for me, NSAllocateMemoryPages failed disappears, memory usage < 600M, but syncing with large data broken on some device.

200MB Sqlite + 70GB assets

  • M1 Max macOS Catalyst(sync success) ==> 3-5 hours(most time for download) + low cpu usage
  • iPad Pro 12.9 5th 16g RAM(sync success) ==> 20 hours active + 5 crashes + half time 100% CPU
  • iPhone Xs  Max(sync failed) ==> 40+ hours syncing with 15gb downloaded + 10 crashes and sync errors + half time 100% CPU

Yes. The memory issue is fixed for me too in 15.5. Still have a couple of users reporting sync failure though. Not sure why and am chasing it up with them as far as I am able. I have closed my FB as the specific issue I reported appears to have been fixed.

I'm still getting this error. Not sure how to fix, but I submitted a bug report.

NSPersistentCloudKitContainer - Import failed because applying the accumulated changes hit an unhandled exception
 
 
Q