Search code examples
icloudcloudkit

CloudKit Dashboard: Deploy Schema to Production fails with "There was a problem loading the environment’s status"


Note: This is not new, but I have some new insights on it.

For about three weeks now I regularly try to deploy the development-schema of my CloudKit Container to production, using the CloudKit Dashboard:

enter image description here

It spins for exactly a minute to then tell me "There was a problem loading the environment's status"

enter image description here


This is not new, many other questions face this as well:

Apple support told me to

  • look at https://developer.apple.com/forums/thread/656723 (try again after a day with stable network)
  • use Safari and resetting browser settings to clear cache and cookies
  • "You may also try creating a new CloudKit container, rebuilding your schema, and then try again." => obviously doesn't work, because users have data on production

Solution

  • TL;DR:

    Kill the timeout by running this in the console:

    var id = window.setTimeout(function() {}, 0);
    
    while (id--) {
        window.clearTimeout(id); // will do nothing if no timeout with id is present
    }
    

    (the response is undefined — that's okay)


    How I got there

    So I started to look at the requests the site makes to the backend when I click "deploy". Chrome shows that the request to

    https://p39-ckdatabasews.icloud.apple.com/r/v3/user/<container-name>/production/public/admin/deployment/status?team_id=<team-id>
    

    is cancelled after 1.0 min.

    enter image description here

    Insight 1

    The problem is with the production schema. I had used the Reset Development Environment before to make sure I hadn't messed that up myself, but this would have spared me that.


    I used the Copy as cURL command (in Chrome, because it also copies the auth cookies, which Safari does not) and ran it in Terminal.

    Interestingly, that does respond after 1'37 min. That's also what the X-Apple-Edge-Response-Time: 97244 header says.

    enter image description here

    If you know what to look for, the console will also tell you the the request timed out:

    enter image description here

    Insight 2

    The server takes too long to respond (> 1min) and the client script times out (at 1 min)

    Note: You can also get a response by right-clicking the request in Chrome and choosing "Replay XHR".


    Solution

    I tried to understand the JavaScript that sends the XHR request and modify the timeout, but I failed. However, you can apparently clear all timeouts that exist with

    var id = window.setTimeout(function() {}, 0);
    
    while (id--) {
        window.clearTimeout(id); // will do nothing if no timeout with id is present
    }
    

    (from https://stackoverflow.com/a/8860203)

    Running that while waiting for the response actually worked for me!