77

What does this error message mean and how do I resolve it? That is from console of Google Chrome v33.0, on Windows 7.

Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH           http://and.img.url/here.png

I'm trying to change the images' src attribute using jQuery. For example like this (simplified):

$('.image-prld').attr('src', someDynamicValue);

There are about 30 images on the page. And the above error is happening for random images every time when I reload the page. But sometimes it is working well for all the images, without any error.

When this error happens, the particular image is displaying like this:

enter image description here

However, when I open the link next to the error message on a new tab, the image is loading, which says me logically that the images is valid and it exists.

user3332579
  • 3,111
  • 3
  • 17
  • 21
  • 1
    Just a guess, your browser is receiving a `content-length` header from the server, that does not equal the actual length of the content. – Niet the Dark Absol May 07 '14 at 15:22
  • Do you experience this error on any other websites than your own? – Kevin B May 07 '14 at 15:23
  • No, I don't. I don't see this message on other websites. – user3332579 May 07 '14 at 15:26
  • It seems that I only see this on Chrome. I've tried FF and IE, and can't reproduce this after about 15 reloads of the pages on each browser. – user3332579 May 07 '14 at 15:27
  • @Niet the Dark Absol, then what is the story about successful image load on another tab? The same URL, from different pages/tabs, one loads, another fails. – user3332579 May 07 '14 at 15:29
  • Have you tried this from any other computers? I've seen this kind of issue be related to the client computer before, that's what I'm trying to rule out. – Kevin B May 07 '14 at 15:30
  • @Kevin B, no. But I can't understand what is the relation between OS & Hardware and the error message. Or you have any possible use cases where this error can be issue of my computer? – user3332579 May 07 '14 at 15:35
  • https://productforums.google.com/forum/#!topic/chrome/5vv1Cp9hJZQ The fact that it's only affecting chrome is what has me suspicious. – Kevin B May 07 '14 at 15:35
  • Hmm... I've no antivirus at all on my computer... – user3332579 May 07 '14 at 16:37
  • I have this error as well when running angular cli ng serve on a remote server and trying to access it locally. Running it locally is working fine. – A.W. Aug 07 '17 at 06:08

13 Answers13

48

Docker + NGINX

In my situation, the problem was nginx docker container disk space. I had 10GB of logs and when I reduce this amount it works.

Step by step (for rookies/newbies)

  1. Enter in your container: docker exec -it <container_id> bash

  2. Go to your logs, for example: cd /var/log/nginx.

  3. [optional] Show file size: ls -lh for individual file size or du -h for folder size.

  4. Empty file(s) with > file_name.

  5. It works!.

For advanced developers/sysadmins

Empty your nginx log with > file_name or similar.

Hope it helps

Valijon
  • 12,667
  • 4
  • 34
  • 67
mrroot5
  • 1,811
  • 3
  • 28
  • 33
  • 3
    Save 10 key strokes at step 4 with just > file_name ;) – Ian Ellis Apr 13 '17 at 21:16
  • Thanks @IanEllis. I added advanced developer / sysadmin option – mrroot5 Sep 28 '18 at 09:54
  • I had this issue, but not sure why it occurs. I had a medium size image that failed to load only in Chrome. I had plenty of diskspace. Once I followed above, it worked. If there is plenty of diskspace, why does this ocurr? Also, using nginx only, not docker. – Raymond Carl Nov 11 '18 at 13:40
  • Hi @nordicray! With Chrome sometime I had problems with cache. Try to disable the cache or change your code to avoid caching. – mrroot5 Nov 12 '18 at 08:32
  • 2
    `Disk space` is the keyword! – matewka Dec 19 '18 at 14:48
42

This error is definite mismatch between the data that is advertised in the HTTP Headers and the data transferred over the wire.

It could come from the following:

  1. Server: If a server has a bug with certain modules that changes the content but don't update the content-length in the header or just doesn't work properly. It was the case for the Node HTTP Proxy at some point (see here)

  2. Proxy: Any proxy between you and your server could be modifying the request and not update the content-length header.

As far as I know, I haven't see those problem in IIS but mostly with custom written code.

Let me know if that helps.

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
  • 1
    Yeah but how do you force Chrome to ignore the error and display/render the page anyways? The entire document has been transfered, just the length doesn't match. It works in Curl (it just doesn't render). – Chloe Oct 13 '16 at 15:57
  • 13
    You don't. Forcing it is like patching a symptom. Find the root cause, fix it and enjoy a saner web. – Maxime Rouiller Oct 13 '16 at 16:02
  • 2
    The server is inside of an old router! I don't have access! – Chloe Oct 13 '16 at 16:11
  • _"definite mismatch between the data that is advertised in the HTTP Headers"_ exactly - just happend to me due to invalid JSON returned from the backend.. – iLuvLogix Sep 21 '21 at 09:56
  • simply trying to refresh the browser may resolve it. – klewis Jan 13 '22 at 18:14
39

It could be even caused by your ad blocker.

Try to disable it or adding an exception for the domain from which the images come from.

Joe Valeriana
  • 610
  • 7
  • 11
  • 1
    Right on! Any idea why this happens? Is it because ad-blockers inject code into every file that is fetched? If so then why does this not happen for every single file requested? – jahackbeth Feb 18 '15 at 12:09
  • Actually I do not know how adblockers exactly works (which is why I used the conditional). Maybe is something related to the filters, so the code is not injected on every single file, but only on files that match a specific pattern described in the filters.. – Joe Valeriana Feb 18 '15 at 15:20
  • Wow, question has been asked 5 years ago. Yet, it helped in my situation. –  Jul 06 '19 at 06:41
19

This can be caused by a full disk (Ubuntu/Nginx).

My situation:

vdB
  • 251
  • 2
  • 4
  • in my situation, the disk is not full, but the script is useful. might be the temp folder is full? – echo Jul 05 '21 at 02:32
  • 1
    @echo that could be the case if the tmp folder has it’s own ‘disk’? If you check with “df -h” you should see if that is the case? If you have many files on disk it may also be that you ran out of inodes (I believe “df -i” should show if that is the case). If either shows a ‘full disk’ cleaning up probably helps ;) – vdB Jul 06 '21 at 05:43
4

In my case I was miscalculating the Content-Length that I advertised in the header. I was serving Range-Requests for files and I mistakenly published the filesize in Content-Length.

I fixed the problem by setting Content-Length to the actual range that I was sending back to the browser.

So in case I am answering to a normal request I set the Content-Length to the filesize. In case I am answering to a range-request I set the Content-Length to the actualy length of the requested range.

Tobias Gassmann
  • 11,399
  • 15
  • 58
  • 92
4

This is what worked for me.

        proxy_buffer_size   1M;
        proxy_buffers   4 1M;

I increased the size of the above parameters in nginix proxy.conf file. Here, nginix is working as a proxy for my microservice-based applications.

  • 1
    Adding proxy_buffer_size and proxy_buffers fixed the issue for me. However, seems like your proxy_busy_buffers_size directive is incomplete. Wasn't required for my use case though it seems. – Form Dec 25 '21 at 18:58
2

In my case I was modifying the request to append a header (using Fiddler) to an https request, but I did not configure it to decrypt https traffic. You can export a manually-created certificate from Fiddler, so you can trust/import the certificate by your browsers. See above link for details, some steps include:

  1. Click Tools > Fiddler Options.
  2. Click the HTTPS tab. Ensure the Decrypt HTTPS traffic checkbox is checked.
  3. Click the Export Fiddler Root Certificate to Desktop button.
Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
1

It is definitely has to do something with disk space on your server clearing the log folder worked for me. follow these steps

1. go to nginx log directory
   cd /var/log/nginx
2. delete all the older log
   rm *.gz               
3. emplty error log
   truncate -s 0 error.log.1 
4. empty access log
   truncate -s 0 access.log.1
shyam yadav
  • 214
  • 1
  • 10
0

In my case it was a proxy issue (requests proxied from nginx to a varnish cache) that caused the issue. I needed to add the following to my proxy definition

        proxy_set_header Connection keep-alive; 

I found the answer here: https://stackoverflow.com/a/55341260/1062129

George
  • 2,860
  • 18
  • 31
0

If this is related to docker, try stopping the erroneous container and starting a new container using docker run command from the same image.

Lanil Marasinghe
  • 2,785
  • 24
  • 24
0

If anyone struggle with that problem using docker + nginx, it could be permissions. Nginx logs shown error:

2019/12/16 08:54:58 [crit] 6#6: *23 open() "/var/tmp/nginx/fastcgi/4/00/0000000004" failed (13: Permission denied) while reading upstream, client: 172.24.0.2, server: test.loc, request: "GET /login HTTP/1.1", upstream: "fastcgi://172.28.0.2:9001", host: "test.loc"

Run inside nginx container(path might vary):

chown -R www-data:www-data /var/tmp/nginx/
Biegacz
  • 61
  • 3
0

Running docker system prune -a did the trick for me. I did not have any luck rebuilding my containers or following @mrroot5's answer, although those would seem to achieve similar things.

ambe5960
  • 1,870
  • 2
  • 19
  • 47
0

This error also occurs if your project folder is located in Google Drive or OneDrive folder and one of your project files that you are calling in your code is still online only(no local copy has been downloaded yet). Just make sure all your project files have local copies downloaded so that they are accessible to your code.

Emo
  • 103
  • 1
  • 8