cached files with wrong size

Maxim Dounin mdounin at mdounin.ru
Fri Oct 19 10:32:10 UTC 2012


Hello!

On Fri, Oct 19, 2012 at 11:10:20AM +0300, Anatoli Marinov wrote:

> *Hello colleagues,
> I have some troubles when caching (with proxy cache) some objects
> which don't
> have content-length header. It happens with gzipped .js or .css
> files. Usually
> these files don't have content-length because its size is not known
> when headers
> are sent.
> 
> If the connection between proxy server and origin behind it
> disconnects during
> file transfer the file will be checked if it has correct size only if
> content-length exists. Otherwise the file will be cached normally even it
> does not have correct size.
> 
> In this case corrupted file will be sent to the browser and probably
> it will break normal behaviour of a served website.
> Do you know a solution for such kind of issues?*

As soon as the connection is closed uncleanly (i.e. was reset or 
times out), there should be no problem with proxy_cache: nginx 
will detect there is an error and won't cache the response.

If the connection is closed cleanly (e.g. your OS does a clean 
connection close on a behalf of an unexpectedly terminated app, or 
an unexpected connection close is hidden behind another proxy 
layer), there is a problem though: one can't detect if a response 
is complete with HTTP/1.0 without Content-Length present.

With HTTP/1.1 situation is a bit improved, as it has 
chunked transfer-coding.  Though as of now nginx doesn't try to 
take it into account when caching files even if HTTP/1.1 to 
backends is activated using proxy_http_version directive.

I've already suggested a way to improve things here:
http://mailman.nginx.org/pipermail/nginx-devel/2012-September/002699.html

It should improve things with HTTP/1.1 used, though no one tried 
to actually do it yet, and I don't have time to dig into this 
right now.


-- 
Maxim Dounin
http://nginx.com/support.html

p.s. Please don't use html to post here.  Thanks.



More information about the nginx-devel mailing list