App constantly refreshing after an update

Hi Elie

Sorry for the late responce. I have been testing different configurations for the past week. I used your guide above for scaling, as well as this guide: https://meteorhacks.com/how-to-scale-meteor.html

I also got advice from a more experienced Meteor developer than I, on how to optimize my code. From the Harida stats it looks like all has been fixed and I have had no more constant refreshes/slow downs.

Once the system has been stable for a couple of weeks I will report back, but it looks like the refreshes may have been caused by bad coding on my side :frowning:

I still love Meteor and will definitely continue building with it.

Just to update people, I have continued to see this problem on a subdomain.
I changed my nginx settings but it didnā€™t seem to help.

On the regular domain, I donā€™t seem to have this issue.

Itā€™s a mystery what this problem is. It can be a real killer especially
when you have a fair number of users and run the project on the side with
limited time to investigate.

Iā€™m still seeing this as well. Scares the crap out of me :smiley: .

I have the same problem since 2 daysā€¦ before everythings work well.
I use cloudflare for my cache system.

The only solution to stop this refresh is to clear the cache (CTRL+F5)ā€¦

Was there any responce on this by mdg?
(or they are just smiling and waiting the Galaxy customers :slight_smile:

1 Like

The same issue is present on Galaxy.

1 Like

I think Iā€™ve solved the problem (hopefully).

In nginx config you have to set everything except the JS and CSS files to be Cache-Control no-store, because if you are using a router the main HTML file can be loaded from multiple locations.

I have two location blocks, one: location / {
And the other: location ~ /.*\.(css|js)$ {

Both have the proxy lines in. The first has add_header Cache-Control no-store;.

Let me know if this works for you.

3 Likes

Wondering if Galaxy has this problem too, since users donā€™t set nginx stuff for Galaxy.

I will give your solution a try tomorrow.

Iā€™ve experienced this problem on Galaxy.

1 Like

@topicly

Both have the proxy lines in. The first has add_header Cache-Control no-store;.

I think that this disables client caching at all. As a result the bundled js gets downloaded everytime, a deal breaker for mobile / low-bandwidth environments.

It doesnā€™t. pad pad pad

You are right @topicly

I misunderstood

and just set cache-control on my single / location.

I just copied the content from / to ~ /.*\.(css|js)$ and added add_header Cache-Control no-store; to /
Iā€™ve no idea if it works (will update to this thread), but js and css files are cached now.

update

This did not solve the problem, itā€™s still refreshing.

Finally Iā€™ve found a working solution. According to https://github.com/meteor/meteor/issues/5769#issuecomment-215977417 nginx must not handle any caching at all.

This was the location block which caused refresh loops:

    location / {
        proxy_pass http://app;
        proxy_redirect      off;
        proxy_set_header    Host              $host;
        proxy_set_header    X-Real-IP         $remote_addr;
        proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;

        # WebSocket specific
        proxy_http_version 1.1;
        proxy_set_header    Upgrade           $http_upgrade;
        proxy_set_header    Connection        "upgrade";

        # this setting allows the browser to cache the application in a way compatible with Meteor
        # on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days)
        # the root path (/) MUST NOT be cached
        if ($uri != '/') {
            expires 30d;
        }
    }

A lot tutorials and boilerplates advise to use this faulty configuration

        if ($uri != '/') {
            expires 30d;
        }

which is actually the problem. So just delete it.

Working configuration:

    location / {
        proxy_pass http://app;
        proxy_redirect      off;
        proxy_set_header    Host              $host;
        proxy_set_header    X-Real-IP         $remote_addr;
        proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;

        # WebSocket specific
        proxy_http_version 1.1;
        proxy_set_header    Upgrade           $http_upgrade;
        proxy_set_header    Connection        "upgrade";
    }
1 Like

Iā€™ve been having this problem on mobile/android but not on OSX laptop - so hey I looked through my code for this nginx if ($uri != ā€˜/ā€™) { expires 30d; } but I couldnā€™t find it. What file is this in? And if this isnā€™t a part of my project and Iā€™m having the same problem, it could be something else. Whatā€™s up? Thanks for your help everybody! Iā€™m new-ish to meteor and deployed my first app (a very simple one) today.

I just tried adding appcache to my project and got an infinite reload locally. I wonder if this has anything to do with the issues. For now Iā€™ve just removed appcache.

Just another datapoint on this. We recently updated our 1.2.x app to 1.4 (we tested 1.3, but not in production). We are seeing constant reloads whenever we run our app after using ā€˜meteor buildā€™, but not if we run it using ā€˜meteor runā€™. I can replicate this on my own laptop (OSX) as well as on out development testing servers (dockerized debian). Neither are using a proxy.

Point is, even if it is affected by nginx, nginx isnā€™t the cause.

Iā€™m wondering if it is loading-order issue as Iā€™ve seen some peculiarities in our logging that makes me think class may be being instantiated before they are defined. Iā€™m seeing objects that just arenā€™t there, even though they should be created at startup and that is showing in our logs as empty arrays, for example. Strange stuff and it takes a long time to track down because I have to do a full build each time I want to test. ( What is this, C++? lol )

Well thatā€™s great news if you can produce a reliable reproduction of the
problem. Would be worth posting the issue on github and finally getting
someone from MDG to look into it.

Maybe I spoke too fast. I upgraded my local mongo install to 3.2.9 (was 2.6) and now it has suddenly stopped. Iā€™m going to try on our development testing server to see if it still has the problem (it is still running mongo 2.6). If it is, at least weā€™ve isolated one possible cause of the problem.

Was there any more update on this issue? We are also experiencing this with our Production application and it causing some frustration for our users :frowning:

We have removed the caching from our nginx configuration file but it did not seem to helpā€¦

I have still been seeing it on my site when deploying to a subdomain, but
not to the regular domain.

Itā€™s an extremely painful problem and no one seems to have come up with a
solution.