33

I've got an app that runs fine locally, but barfs in production. (Classic problem, right?)

In production, the JS isn't firing correctly. When I open up the browser console, I see this error:

net::ERR_CONTENT_LENGTH_MISMATCH

When I look in the network tab of Developer Tools, is shows that it failed on a GET request for text/html.

It's a cryptic error. I've only found two other SO posts that even mention is and they're unsolved. (For the interested: first post and second post)

Any idea (1) what it means or (2) how to resolve it?

Community
  • 1
  • 1
Ben Downey
  • 2,575
  • 4
  • 37
  • 57

5 Answers5

35

I am getting Error: net::ERR_CONTENT_LENGTH_MISMATCH

Have a look at your server logs to determine what the real issue is.

For me the problem lay somewhere between nginx and file permissions:

  • tail -f /usr/local/var/log/nginx/error.log or run nginx -t to determine your conf location, where you could specify a custom log path.
  • refresh the asset in your browser, eg http://localhost:3000/assets/jquery/jquery.js

You may see something like this in the logs:

"/usr/local/var/run/nginx/proxy_temp/9/04/0000000049" failed (13: Permission denied) while reading upstream for file xyz

Heres how I fixed:

sudo nginx -s stop
sudo rm -rf /usr/local/var/run/nginx/*
sudo nginx
random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
  • 5
    In my case Nginx was running as a reverse proxy and I simply runned out of disk space. One look at Nginx logs was enough. Thanks. – Tad Lispy Nov 20 '14 at 14:40
  • 1
    This also solved my issue for getting "net::ERR_INCOMPLETE_CHUNKED_ENCODING" wherein my node server was cutting the file stream short. – Michael Angstadt Feb 28 '15 at 00:15
  • 1
    Solved for me too. I was getting ERR_CONTENT_LENGTH_MISMATCH when i trying to directly access an image like: http://url.to/assets/image.png. Went through the same steps and after deleting cache folder, the error was gone. Thanks! – felipecao Mar 16 '15 at 10:24
  • 1
    Removing `proxy_temp` then reloading `ngix` fixed it for me. – Zeniu Zhu Mar 24 '15 at 03:40
6

According to this bug report, that error occurs when an external resource length does not match the Content-Length header given in the response.

This might occur because of a misconfigured server, or (as a stretch) maybe some BOM characters got put into the file, or maybe even different lines endings (are you writing on a DOS machine and deploying to a UNIX machine?) may cause issues.

Hope this helps.

omghaxzs
  • 96
  • 1
  • 3
  • Older response, but I write in node.js (using express.js) on Windows, and since moving the code to an Ubuntu server, I experienced this issue with several content files (not sure which caused the issue). Using dos2unix solved the problem for me. – matth Jan 18 '16 at 14:24
1

I had a similar issue when trying to interpret JSON results. It turned out that somewhere along the line an odd character landed in the database - in this instance the culprit was "â??". It is not clear how this value arrived in the database, but it is likely related to HTML encoding issues - "Â" character showing up instead of " " Either way, after removing the odd characters, the problem was solved.

Community
  • 1
  • 1
Gert
  • 39
  • 4
1

I had similar issue [crit] 6889#0: *14817 open() "/var/cache/nginx/proxy_temp/3/02/0000000023" failed (13: Permission denied) while reading upstream

it was because Nginx worker process were not able to access folder /var/cache/nginx/proxy_temp/ - I just changed the folder permissions and everything started working

JRomio
  • 2,407
  • 3
  • 26
  • 27
  • I do `sudo chmod -R 777 /var/lib/nginx/proxy/ ` and everything works fine. There maybe some security issue about that. Can someone else explain it to me? – Yakob Ubaidi Jun 04 '15 at 05:17
  • dont setup 777...just give read permission to user running Nginx ( may be by adding it to owner group of that folder ) – JRomio Jun 05 '15 at 20:11
1

I had similar issue developing locally on MAMP and using Chrome as browser. Same problematic websites on the live servers had no such issues. First I thought it was MAMP that was playing around and I checked settings like PHP versions mismatch, apache version etc., reinstalled, but the issue remained. At the end I just switched to using Brave browser (was delaying the shift to Brave for a while anyway) and that fixed it for me.

Hope this helps.

S.Simeonov
  • 261
  • 3
  • 5