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?

Replies

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!

  • I have encountered this issue recently and filed a bug report:  FB9761973 Can you please follow up. This problem started a few days ago and is affecting only some users.

  • I have encountered this issue recently and filed a bug report:  FB9761973 Can you please follow up. This problem started a few days ago and is affecting only some users.

  • I see this too for many users.

    <CKError 0x283f54ae0: "Service Unavailable" (6/2022); "Request failed with http status code 503"; uuid = 654A94C9-68F6-49A6-ABF5-85386D873686; Retry after 30.0 seconds>

    It's annoying and throws a wrench deep into my code. Fortunately I'm now migrating away from iCloud to my own backend and this is part of my "get all data from iCloud and migrate" process. Still, I have to tell users that Apple's code is buggy. Interesting that even after 10+ years even basic queries fail this spectacularly. And no follow up from Apple's folks as is normal. Filing bugs is pointless as nobody ever reacts to them and fixes take years to appear. Avoid Apple's backend stuff if you can, as they don't take it seriously.

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!