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}}
Post not yet marked as solved Up vote post of lights Down vote post of lights
5.8k views

Replies

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?

  • Yeah, there is something still broken deep down with CloudKit since beta 4. As it's now RC I've submitted a TSI with Apple to (hopefully) get some one-on-one interaction with SOMEONE at Apple.

Add a Comment

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

A TSI is requested.

  • If the problem is related to the problem I and others are having (and I think it is) then the last update from a 'Framework Engineer' suggested that the 'next 15.1 beta' will fix the issue. I initially misinterpreted this as the first 15.1 beta as I had not yet noticed there was one, but I think they mean it will be fixed in iOS 15.1 beta 2 which should be out any day now. I really, really, really hope they've fixed these CloudKit/Core Data issues as it's having an impact on my users' data already. Fingers crossed that it will all start syncing again normally when 15.1 is released to the public!!

  • I should add that my TSI received a reply effectively saying what the Framework Engineer said on these forums - wait for 15.1 beta 2 (and Monterey beta 8)

  • iOS 15.1 beta 2 does not fix it.

Add a Comment

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.

  • Can I have your mail address for debug? My address is feedback + @ + lights.app.

  • FB9659774

  • Sqlite file is not stored in default folder but AppGroup such as /private/var/mobile/Containers/Shared/AppGroup/F5E9858B-BFA8-43C0-8648-B6FB169A4D98/Model.sqlite, app container can not be download from Xcode.(ps: change sqlite path or not is not related to this problem)

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.

  • Same here. iOS15.3 Beta still creating this error and preventing syncing. Reported as FB9859660

  • @lights - I wonder if you have found any solution? I haven't yet!

  • not solved in iOS 15.3 final either. seems it only happens when pulling down data from the private database in the cloud. i'm not getting these issues with the public database.

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!!

  • I just wanted to let you know that I did end up filing a bug report and quoted yours. I wish Apple would give us some kind of ETA on a fix…what an awful bug.

Add a Comment

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

  • Not syncing with iOS 15.5 (without moving app to background and move it back). I don't know what to say, NSPersistentCloudKitContainer was introduced few years ago and it is still has issues. Even when it seems like it started to work, then new minor version of iOS comes and breaks it again.

Add a Comment

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.

  • I should have mentioned I've noticed it happens when I have more than 50 or so objects. When it's fewer I still see the "Import failed because applying the accumulated changes hit an unhandled exception., NSUnderlyingException=Batch finished processing with pending changes in the moc. This prevents the context from being reset and purging rows / snapshots from memory. Please save at the end of each batch." error, but the data syncs.

Add a Comment