13

The problem

My website fails to load random images at random times. Intermittent failure to load image with the following error in console:

"GET example.com/image.jpg net::ERR_CONTENT_LENGTH_MISMATCH"

Image either doesn't load at all and gives the broken image icon with alt tag, or it loads halfway and the rest is corrupted (e.g. colors all screwed up or half the image will be greyed out).

Setup

Litespeed server, PHP/mySQL website, with HTML, CSS, Javascript, and JQuery.

Important Notes

  • Problem occurs on all major web browsers - intermittently and with various images.
  • I am forcing UTF-8 encoding and HTTPS on all pages via htaccess.
  • Hosting provider states that all permissions are set correctly.
  • In my access log, when an image fails to load, it gives a '200 OK' response for the image and lists the bytes transferred as '0' (zero).
  • It is almost always images that fail to load but maybe 5% of the time it will be a CSS file or Javascript file.
  • Problem occurred immediately after moving servers from Apache to Litespeed and has been persistent over several weeks.
  • Gzip and caching enabled.
user3100907
  • 255
  • 3
  • 13
  • Do you also have gzip enabled for images? This is usually not recommended as you don't profit much, but waste a lot of CPU. – alesc Jun 13 '15 at 16:02
  • I was wondering that myself, is there a quick way to check? Sorry, I am not much of a web admin... – user3100907 Jun 13 '15 at 16:08
  • You can use an online tool, such as [checkgzipcompression.com](http://checkgzipcompression.com/) (first google hit). – alesc Jun 13 '15 at 16:12
  • GZIP not enabled for single image. GZIP enabled for full webpage. I think this is normal behavior. Good thought, thanks for the help though. – user3100907 Jun 13 '15 at 16:20
  • Is there a proxy or load balancer involved or anything else in the stack you can tell us – Jordan Jun 15 '15 at 19:00
  • R u generating the images through PHP script (GD / imagemagick) or its a static images in a folder? – Sudip Pal Jun 15 '15 at 19:24
  • Also, you said 'hosting provider' - Do you have complete control (i.e. console access) of this server? – Jordan Jun 15 '15 at 19:25
  • Sorry for the late response. Jordan- no proxy or load balancer or anything else out of the ordinary. It's all very conventional. Sudip - static images, nothing is generated dyanamically. Jordan - I do have root access but have never messed with it. Anything I should try? – user3100907 Jun 15 '15 at 22:49
  • Anything intersting in the Litespeed error logs around the time of the error? If not, the next step might be a network trace (using tcpdump) of a failing session to see if a 3rd party is breaking your connection. – Peter Brittain Jun 17 '15 at 17:45
  • Peter - Thanks. I'll do both tonight and report back. – user3100907 Jun 17 '15 at 18:20
  • Litespeed or openLitespeed? If openlitespeed, version 1.3.11 or 1.4.8? – Protomen Jun 18 '15 at 04:09
  • Guilherme - it is LiteSpeed Web Server version 4.2.22 – user3100907 Jun 18 '15 at 13:56

4 Answers4

1

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.
  2. Proxy : Any proxy between you and your server could be modifying the request and not update the content-length header.

This could also happens if setting wrong content-type.

As far as I know, I haven't see those problem in IIS/apache/tomcat but mostly with custom written code. (Writing image yourself on the response stream)

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.

Zahid Riaz
  • 2,879
  • 3
  • 27
  • 38
  • I'll ask my host about the bugs and proxy as I have no knowledge of that. I did see other people online point out the ad-blocker issue. It has been disabled and still functions with or without it. It also still happens on other browsers on which I don't use an ad blocker and have never installed one. Thanks. – user3100907 Jun 18 '15 at 13:58
0

Suggest accessing the image as a discrete url using cURL, eg php testCurlimg >image.log 2>&1 to see exactly what is being returned by the server. Then you can move upon level to test the webpage php testCurlpg >page.log 2>&1 to see the context for mixed data

jobeard
  • 129
  • 6
0

I just ran into this same ERR_CONTENT_LENGTH_MISMATCH error. I optimized the image and that fixed it. I did the image optimization using ImageOptim but I'm guessing that any image optimization tool would work.

Collin Krawll
  • 2,210
  • 17
  • 15
0

Had this problem today retrieving images from Apache 2.4 when using a proxy I wrote in php to provide a JWT auth gateway for accessing a couchdb backend. The proxy uses php fsockopen and the fread() buffer was set relatively low (30 bytes) because I had seen this value used in other peoples work and I never thought to change it. In all my failing JPG (JFIF) images I found the discrepancy in the original versus the image served was a series of crlf that matched the size of the fread buffer. Increased the byte length for the buffer and the problem no longer exists.

In short, if your fread buffer streaming the image is completely full of carriage returns and line feeds, the data gets truncated. This possibly also relates to the post from Collin Krawll as to why image optimization resolved that problem.