Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with missing files upon server update #14

Open
elie222 opened this issue Aug 15, 2017 · 15 comments
Open

How to deal with missing files upon server update #14

elie222 opened this issue Aug 15, 2017 · 15 comments

Comments

@elie222
Copy link

elie222 commented Aug 15, 2017

If you have 2 load balanced Meteor instances running for example, and you've done an update and 1 of the instances has been updated, but the other instance is still waiting to be updated, how would this work exactly using Cloudfront?

Cloudfront would try and grab the pages from the Meteor url, but may be connected to the wrong Meteor server that the user is connecting to and then the site will not be able to load. This is a real issue we've run into and was wondering if this package could help with that at all.

@kulttuuri
Copy link

I believe meteor serves the files with version hash added to the files so when you have cloudfront setup correctly it should serve old and new files. This doesn't however work if images or static assets do change.

@elie222
Copy link
Author

elie222 commented Aug 15, 2017 via email

@kulttuuri
Copy link

Are your load balanced servers running on same domain? So for ex. Users always connect to example.com and example.com has nginx or something similar that connects in the background to 1.example.com @ 2.example.com?

@elie222
Copy link
Author

elie222 commented Aug 15, 2017 via email

@kulttuuri
Copy link

Could you then use same cloudfront endpoint for both servers? That way it would have both old and new content in the cache.

@kulttuuri
Copy link

BTW I hit similar problem earlier in the development on our production server. We're also running load balancers servers on similar scenario. I think it was the query parameter setting that I had to configure on Cloudfront correctly to get this working right (it was showing blank white screen for some users)

@elie222
Copy link
Author

elie222 commented Aug 16, 2017 via email

@elie222
Copy link
Author

elie222 commented Sep 11, 2017

@kulttuuri what query param did you set?

@elie222
Copy link
Author

elie222 commented Sep 11, 2017

What we're seeing is that Cloudfront will cache the result and if the result isnt found it will cache that and then even once all servers have updated to the latest version, users wont be able to access the site.

@maxkferg
Copy link

maxkferg commented Sep 11, 2017

@elie222. This was a problem that came up in the original development and testing of the package.
From memory, our first attempt at fixing this was to return a proper 404 for missing static files f824449.
If the CDN is configured NOT to cache 404 responses, then this problem will largely go away:

  1. A new server with new content will come online
  2. Meteor will request the new static content
  3. If the content is fetched from an old server then it will return a 404. The page will be blank. The resource will not be cached*
  4. If the content is fetched from a new server then everything will be fine and the new content will be cached.

*Step (3) may be repeated a few times until step (4) is reached

So as a first solution I suggest that you make sure 404 responses are not being cached. There is definitely an opportunity to handle this situation better - although it may be outside the scope of this package. As @elie222 and @kulttuuri mentioned, this is a problem at the load balancer level. I am not sure how to reroute load balancer traffic to old/new servers in a reliable way. Suggestions are welcome

@jlichti
Copy link

jlichti commented Feb 19, 2018

I handle this by having a staging server that I always deploy first (and then I snapshot and roll out to production). I have my CDN point to the staging server with a * behavior match on CloudFront just above the default.

If I'm not doing any production deploys for a while I just change my staging server behavior to DISABLED so the CDN will hit my load balancer.

@jfurneaux
Copy link

Did anyone come up with an answer to this that avoids having a separate environment?

@elie222
Copy link
Author

elie222 commented Sep 29, 2018

Yeah. This is really annoying. It means you can never have servers running separate versions. It can also take a minute or so for a set of 16 servers to update for example, during this time the latest servers may not be able to load.

I think the way to properly solve this is to upload the files to an S3 bucket and have Cloudfront pull from there. As soon as a build finishes you upload the files to S3 so Cloudfront always has them. I think something like this is possible although I've never tried it and could be a little tricky to set up.

@elie222
Copy link
Author

elie222 commented Sep 29, 2018

How we've been dealing with this over the past year is:

  1. Turn off CDN setting
  2. Deploy
  3. Turn on CDN setting
  4. MUP Reconfig

If you're not using MUP then you can't always do the simple mup reconfig to update settings.

@klokie
Copy link

klokie commented Mar 15, 2019

hi! Did you ever get this to work without having to toggle the CDN settings upon deployment? We're using Galaxy + CloudFlare, following that procedure is not trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants