Why am I getting Service Unavailable Error on all CloudKit queries, HTTP 503, CloudKit error code 6

Viewed 482

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:

CloudKit Console Screenshot

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?

0 Answers
Related