I suddenly started getting a CloudKit errors on all record queries. The CKError.Code is 6 = "Service Unavailable." The errorUserInfo
dictionary on the error is:
["CKErrorShouldThrottleClient": 1, "RequestUUID": B59F1738-B330-4F27-A2AE-3C95572BC9F4, "NSLocalizedDescription": Request failed with http status code 503, "CKRetryAfter": 30, "CKErrorDescription": Request failed with http status code 503, "NSDebugDescription": CKInternalErrorDomain: 2022, "NSUnderlyingError": <CKError 0x60000040c060: "Service Unavailable" (2022); "Request failed with http status code 503"; uuid = B59F1738-B330-4F27-A2AE-3C95572BC9F4; Retry after 30.0 seconds>]
Notably, about 95% of the time in the CloudKit console for this container, I also get a message "Internal Error" when querying records. About 5% of the time I am able to see a few records in the CloudKit console.
I have tried deleting and recreating the CloudKit entitlement. I have tried creating a new CloudKit container. Neither of these helped.
A simplified version of the code that executes the query is as below. I am using the new async CloudKit interface, but I get the same error using privateDB.fetch(withQuery: query)
with a completion handler.
let privateDB = CKContainer.default().privateCloudDatabase
let recordZoneID = CKRecordZone.default()
let predicate = NSPredicate(format: "uuid = %@", uuid.uuidString)
let query = CKQuery(recordType: "Resource", predicate: predicate)
Task {
do {
let (recordResults, cursor) = try await privateDB.records(matching: query, inZoneWith: nil, desiredKeys: ["uuid", "resourceData"], resultsLimit: 5)
guard let (recordID, result) = recordResults.first else { fatalError() }
switch result {
case .failure(let error):
fatalError(error.localizedDescription)
case .success(let record):
guard let resourceAsset = record["resourceData"] as? CKAsset,
let resourceURL = resourceAsset.fileURL,
let resourceData = try? Data(contentsOf: resourceURL)
else { fatalError() }
completion(resourceData)
}
} catch let ckError as CKError {
print(ckError.errorUserInfo)
} catch {
fatalError(error.localizedDescription)
}
}
This application was previously working and I can't pinpoint anything specific I did to break it. Any ideas?
Thank you for your detailed post outlining an issue you discovered in CloudKit. Our engineering teams investigated this issue on the CloudKit backend, and have implemented a fix. You should no longer see these error messages from the CloudKit console, or from devices running your app.
The errors seen here resemble request-throttling that may be affecting a specific user, or the container as a whole. An underlying issue caused an elevated number of these error responses to be returned to your CloudKit apps in certain situations, and has since been resolved. Please verify that you’re no longer seeing this issue on your containers.