Service Unavailable Error on all CloudKit queries, HTTP 503, CloudKit error code 6

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?

Answered by in 702565022

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.

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.

Edit: I apologize I was trying to comment on your post, not submit an answer.

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

Same issue. Looks like it fixed itself for one of my users, still occurring for most though. Very frustrating.

I'm having this same issue with one of my queries now, without changing any code. The other queries in the same app still work normally, except once that failing query is called, then I get a "This operation has been rate limited due to an earlier error" error on all queries for some time.

The developer documentation clearly states "503" is an internal error of CloudKit (https://developer.apple.com/library/archive/documentation/DataManagement/Conceptual/CloudKitWebServicesReference/ErrorCodes.html) and we should just try again :D.

I had the similar issue. I have figured out that my app identifier has 2 iCloud containers attached with. I removed the iCloud container which was not in use.

Steps to edit iCloud container.

  1. Go to your developer account
  2. Certificates, IDs & Profiles
  3. Identifiers
  4. Select your app's identifier
  5. iCloud > Edit Container
  6. Choose the correct iCloud container

This did solve my problem. Hope it works for you too.

We wrote Apple Support and Apple Engineering fixed the problem. It seems it was an issue on our iCloud database.

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.

Service Unavailable Error on all CloudKit queries, HTTP 503, CloudKit error code 6
 
 
Q