CKError - Service Unavailable

I'm repeatedly getting this error on one - but not all - CKQuery operation:


CKError(_nsError: <CKError 0x608000846ff0: "Service Unavailable" (6/2022); "Request failed with http status code 503">)


There's no further useful info in the UserInfo dictionary, including no value for the CKErrorRetryAfterKey.


My code initially queries CloudKit for basically two fields: "name" and "hash". Hash is a hash value for a CKAsset file (on the same record) that I don't want to download unless the hash code indicates that the file has changed.


For all the records whose hash codes indicate that I should download the CKAsset, I prepare the same query in the same code, but add the "json" field and rerun, to download only the json files that I need. I use this predicate, containing an array of the desired CKReferences


NSPredicate.init(format: "recordID in %@", fullRecordsToDownload)


The first query always works, the second always fails with the 503. Every time I repeat, it's the same pattern.


Thus it can't really be that the service is unavailable, right?


How can I diagnose this?

I'm seeing now that if I replace that NSPredicate with


NSPredicate(value: true)


then everything seems to proceed properly.


So then

(1) Why a 503, Service Unavailable CKError, and

(2) Something wrong with that type of predicate in passing an array of CKReferences?

Any time you see an error like that where you're not able to determine what the issue is, you should file a bug report. Please use the iCloud Drive & CloudKit Drive profile found here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=iclou&platform=ios and attach the logs to the bug report. If you can post the bug number here I'll follow up with the CloudKit server team to see what we can find out from our side. Thanks!

Thanks for your response, but to close the loop here, I was able to figure out the issue.


It appears there's a limit to the size of the CKReference array that you can pass in. I had numbers that ranged into 100+, and that's what would trigger the error. I reworked my code to query in smaller chunks - I randomly chose 40 - and everything worked correctly.


There's obviously an issue with the API throwing a misleading "503 Service Unavailable" error in this situation - seems a simple enough issue for Apple Engineering to fix - but I wanted to at least post the resolution for others who might hit this.

It would be great to get a bug filed about this error message. If you can file that with the details of what you found and post the bug number here I'll be sure it gets over to the CK server team. Thanks!

CKError - Service Unavailable
 
 
Q