'Illegal attempt to work with the core-data or default zone in the shared database

The setup:
My app uses CoreData+CloudKit to mirror iCloud content.
I am implementing record zone sharing and am testing it using 2 iPhones. iPhone 1 executes the app standalone, iPhone 2 under Xcode control.
When iPhone 1 user invites iPhone 2 user to share his records, iPhone 2 user can accept the share.
This mirrors as expected the iCloud records to the shared database.

The problem:
During mirroring, I get several times the log:

[error] fault: Illegal attempt to work with the core-data or default zone  
in the shared database: <NSSQLCore: 0x105907720>  
(URL: file:///var/mobile/Containers/Data/Application/  
66941553-40FC-4180-928C-BDF85D44AE84/Library/Application%20Support/Shared)  

I have no idea what is illegal, nor what consequences this illegal attempt has.

Any ideas?

EDIT 1:
When I enable run time breakpoints, the app stops in:

Thread 17 Queue : NSManagedObjectContext 0x283f73b50 (serial)  

at:

+[NSCKRecordZoneMetadata zoneMetadataForZoneID:inDatabaseWithScope:forStore:inContext:error:]   

So it seems that the metadata of the iCloud shared database zone that is used for mirroring cannot be read.

EDIT 2:
One more observation, if zone sharing is active and I lookup my iCloud container in the Dashboard:
If I select Zones, and there the Shared Database, the shared zone com.apple.coredata.cloudkit.zone of type REGULAR_CUSTOM_ZONE is displayed. If I tap on the zone name, the Zone Details should be displayed.
Instead I get the error
„BadRequestException: endpoint not applicable in the database type 'sharedb‘“.
This seems to me to be the same error that I get in my app.



Solution 1:[1]

By now I believe this error can be ignored.
My app uses CoreData+CloudKit mirroring for the private and the shared databases.
It now monitors NSPersistentCloudKitContainer.eventChangedNotification and logs events as follows:

func printSyncEvent(_ event: NSPersistentCloudKitContainer.Event) {
    let id = event.identifier
    let storeID = event.storeIdentifier
    let eventType: String
    switch event.type {
        case .setup:
            eventType = "setup"
        case .import:
            eventType = "import"
        case .export:
            eventType = "export"
        @unknown default:
            eventType = "unknown"
    }
    let startDate = "\(event.startDate)"
    guard let endDate = event.endDate else {
        print("Event: id: \(id), storeID: \(storeID), type: \(eventType), start: \(startDate)")
        return
    }
    guard event.succeeded else {
        let error = event.error!
        print("Event: id: \(id), storeID: \(storeID), type: \(eventType), start: \(startDate), end: \(endDate), error: \(error)")
        return
    }
    print("Event: id: \(id), storeID: \(storeID), type: \(eventType), start: \(startDate), end: \(endDate)")
}  

A sample log (only the relevant parts) looks like this:

PrivateStore: ID = 85D7AF77-64C3-47D6-A30E-06FDD034F6C9
SharedStore: ID = 87582E5F-1F92-4A57-ADEB-E8520190423F

Event: id: 2363CEBA-CF4D-4A10-84A9-6DB0C078C6C0, storeID: 85D7AF77-64C3-47D6-A30E-06FDD034F6C9, type: setup, start: 2022-04-05 09:43:26 +0000
Event: id: 2363CEBA-CF4D-4A10-84A9-6DB0C078C6C0, storeID: 85D7AF77-64C3-47D6-A30E-06FDD034F6C9, type: setup, start: 2022-04-05 09:43:26 +0000, end: 2022-04-05 09:43:27 +0000
Event: id: B0F2EAFE-3FBC-4AAD-B881-DBCCDB1E54E1, storeID: 87582E5F-1F92-4A57-ADEB-E8520190423F, type: setup, start: 2022-04-05 09:43:27 +0000
Event: id: B0F2EAFE-3FBC-4AAD-B881-DBCCDB1E54E1, storeID: 87582E5F-1F92-4A57-ADEB-E8520190423F, type: setup, start: 2022-04-05 09:43:27 +0000, end: 2022-04-05 09:43:27 +0000
Event: id: B5B1577B-671F-4094-914B-BD77C9B9E25B, storeID: 85D7AF77-64C3-47D6-A30E-06FDD034F6C9, type: import, start: 2022-04-05 09:43:27 +0000

Event: id: 7EA39D4B-FC72-428E-AFD3-2C97EFD07D30, storeID: 87582E5F-1F92-4A57-ADEB-E8520190423F, type: import, start: 2022-04-05 09:43:27 +0000
2022-04-05 11:43:28.103640+0200 ShopEasy[50306:2763534] [error] fault: Illegal attempt to work with the core-data or default zone in the shared database: <NSSQLCore: 0x13b021340> (URL: file:///Users/reiner/Library/Developer/CoreSimulator/Devices/0E3AD15A-7079-4BED-82D4-58BB5C26AE61/data/Containers/Data/Application/64189142-A8C8-476D-BD0D-6758E259A100/Library/Application%20Support/Shared)
2022-04-05 11:43:28.103867+0200 ShopEasy[50306:2763534] [error] CoreData: Illegal attempt to work with the core-data or default zone in the shared database: <NSSQLCore: 0x13b021340> (URL: file:///Users/reiner/Library/Developer/CoreSimulator/Devices/0E3AD15A-7079-4BED-82D4-58BB5C26AE61/data/Containers/Data/Application/64189142-A8C8-476D-BD0D-6758E259A100/Library/Application%20Support/Shared)
2022-04-05 11:43:28.108523+0200 ShopEasy[50306:2763534] [error] fault: Illegal attempt to work with the core-data or default zone in the shared database: <NSSQLCore: 0x13b021340> (URL: file:///Users/reiner/Library/Developer/CoreSimulator/Devices/0E3AD15A-7079-4BED-82D4-58BB5C26AE61/data/Containers/Data/Application/64189142-A8C8-476D-BD0D-6758E259A100/Library/Application%20Support/Shared)
2022-04-05 11:43:28.108784+0200 ShopEasy[50306:2763534] [error] CoreData: Illegal attempt to work with the core-data or default zone in the shared database: <NSSQLCore: 0x13b021340> (URL: file:///Users/reiner/Library/Developer/CoreSimulator/Devices/0E3AD15A-7079-4BED-82D4-58BB5C26AE61/data/Containers/Data/Application/64189142-A8C8-476D-BD0D-6758E259A100/Library/Application%20Support/Shared)
Event: id: 7EA39D4B-FC72-428E-AFD3-2C97EFD07D30, storeID: 87582E5F-1F92-4A57-ADEB-E8520190423F, type: import, start: 2022-04-05 09:43:27 +0000, end: 2022-04-05 09:43:28 +0000

Event: id: 2C4409CE-9E46-4F5C-A14E-FF7612FDE3B8, storeID: 87582E5F-1F92-4A57-ADEB-E8520190423F, type: export, start: 2022-04-05 09:43:28 +0000
Event: id: 2C4409CE-9E46-4F5C-A14E-FF7612FDE3B8, storeID: 87582E5F-1F92-4A57-ADEB-E8520190423F, type: export, start: 2022-04-05 09:43:28 +0000, end: 2022-04-05 09:43:28 +0000  

This indicates to me that the errors were created by an import event from the shared database.
There are 4 consecutive errors of the same type (Illegal attempt to work with the core-data or default zone in the shared database) but then the import is finished without error. It seems that the importer retries the import several times until it succeeds.
I am afraid we cannot do anything about it except to ask Apple not to log such errors…

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Reinhard Männer