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?
Please let me know if you find a solution. I am in the same situation. My app (which uses iCloud Drive) has been working work years but this problem has started affecting some of my users in the past few days.
I have the same issue with a relatively small percentage of my users. They are getting 503 errors now, but last year did not. My code hasn’t changed. I’m not even sure how to file a bug report because I cannot replicate the issue on my devices and it’s occurring on a relatively small percentage of my users.
Off topic: @cmonsour do you have a particular reason for storing user's uuid with every CKRecord in their own private database? Every record is going to have the same uuid