question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Versioning no longer Load Balancer friendly

See original GitHub issue

Hi

Upgraded from 0.10 today to 1.2.2 due to some issues I was having on our live servers, and have realised it has created another issue, now with the versioning.

Let’s say you have 2…n servers, that all individually update their code, and run npm run production, they are all set up so they share a session state so, for the most part, it doesn’t matter which server they hit.

In the pre 1.0 versioning you might get a code update that for a short period of time creates an inconsistent state: The browser gets told by server 1 /css/app.5ee7141a759a5fb7377a.css is current, due to true Load Balancing it might try getting it from server 2 which hasn’t quite finished npm run production yet. It gets a 404, no big deal, the browser requests that file next time and either manages to get it from a different server, or the other one had finished processing it.

Post 1.0, this creates a larger issue: The browser gets told by server 1 /css/app..css?id=5ee7141a759a5fb7377a is current, if server 2 hasn’t finished compiling yet, it might serve that client the old CSS code, the browser will cache this old code for days/weeks/months.

If we throw a CDN in the mix (something that I’m planning on doing), this creates an even larger issue, because it is possible in that small window, that it caches the old code (even though cachebusting on the new ID), and will serve that to many browsers. CDN even means that any Load Balancer stickiness (for browsers) is completely off the table as well.

It would be great to have the old versioning back (even as an option),
I realise the query string keeps things a bit tidier, but it does mean in multi-server setups there’s no guarantee that the file version being served is actually the right version - having the file existing/not existing is really the only guarantee here.

Thanks

Ben

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:21
  • Comments:54 (13 by maintainers)

github_iconTop GitHub Comments

30reactions
m-lotzecommented, Jan 31, 2018

I am doing it like this:

const fs = require('file-system');
const del = require('del');
const _ = require('lodash');
const jsonfile = require('jsonfile');

const mixManifest = 'public/mix-manifest.json';

...

.version()
.then(function () {
        jsonfile.readFile(mixManifest, function (err, obj) {
            const newJson = {};
            _.forIn(obj, function (value, key) {
                const newFilename = value.replace(/([^\.]+)\.([^\?]+)\?id=(.+)$/g, '$1.$3.$2');
                const oldAsGlob = value.replace(/([^\.]+)\.([^\?]+)\?id=(.+)$/g, '$1.*.$2');
                // delete old versioned file
                del.sync(['public' + oldAsGlob]);
                // copy as new versioned
                fs.copyFile('public' + key, 'public' + newFilename, function(err) {
                    if (err) console.error(err);
                });
                newJson[key] = newFilename;
            });
            jsonfile.writeFile(mixManifest, newJson, {spaces: 2}, function (err) {
                if (err) console.error(err);
            });
        });
});

It reads the mix-mainfest.json file and copies e.g. app.css to app.hash.css and then writes a new manifest. Also deletes old versioned files. Onyl works if every entry in manifest is versioned.

15reactions
devcircuscommented, Aug 4, 2017

He may be working on something as a convenience, however there nothing broke here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Versioning no longer Load Balancer friendly #1022 - GitHub
Query string versioning can make some load balancers think the content is dynamic e.g like a search and not cache. Laravel Mix is...
Read more >
Issues in HTTP Load Balancing - TechDocs - Broadcom Inc.
Many configurations terminate SSL at the load balancer and use non-SSL on the back-end, because mutually authenticated SSL is uncommon.
Read more >
Loadbalancer.org product roadmap – new features, release ...
We've had a chat about this internally and thought that it would be nice to have ... Using LBCLI on the passive node...
Read more >
Your API versioning is wrong, which is why I decided to do it 3 ...
The problem with versioning REST APIs is that you're taking a local change - this resource no longer works the same way -...
Read more >
Plan Office Online Server - Microsoft Learn
Describes Office Online Server requirements and prerequisites, including HTTPS, certificates, virtualization, load balancing, topologies, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found