I actually spent a lot of time on handling these 503's when I implemented sync in my app, and unless I'm missing something, I think my app is tolerating the recent instability really well.

<🧵>
I AM seeing some recent spikes in underlying sync errors (see image), but it's not translating into failed overall syncs (which I also track but don't have good graphs for), and I have not had any reports of sync failures from users.
I believe the key is handling rate limiting properly, which CloudKit (erroneously) returns as 503 errors. But there are some gotchas to watch out for:

1. The suggested retry period is returned in the userInfo of the error, under the key CKErrorRetryAfterKey.
2. The suggested retry period is too short, and repeating your request after that period will trigger rate limiting again (seriously).

I use the suggested period as a minimum, and use my own exponential backoff instead.
3. If there were multiple errors, they will be returned as a single error with a partialErrorsByItemID value containing the underlying errors. The parent error will not contain the retry information, you need to check the underlying errors.
4. I have seen certain errors (specifically zoneBusy and requestRateLimited) actually omit the CKErrorRetryAfterKey value, and so I have a default value of 30 seconds in case it is missing.
5. Quota exceeded errors (meaning the user is out of iCloud space) seem to erroneously include CKErrorRetryAfterKey values, even though retrying them is not actually going to help. Don't try to retry in that case, just show it to your user.
I've created a gist containing just this retry logic. If you get an error back from a CloudKit request, call timeAfterWhichToRetry(retryCount:) on the error returned, then wait that long before trying the request again. Increment retryCount each time.

gist.github.com/chrisvasselli/…
No guarantees this will fix everything, but so far (**knocks on wood**) things seem to be going well for @Nihongo_App.

Good luck!

</🧵>
After reading more, it looks like there is more going on here than just properly handling the retry timeout. Some accounts are getting 503's on all requests, no matter what.

My tips above won't solve that issue, sorry! I hope it's still helpful in minimizing other sync errors.🙂

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Chris Vasselli

Chris Vasselli Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(