nginx-1.0.4
Maxim Dounin
mdounin at mdounin.ru
Fri Jun 24 07:03:31 MSD 2011
Hello!
On Sat, Jun 18, 2011 at 03:35:31AM +0400, Maxim Dounin wrote:
[...]
> Thank you for details, I was able to reproduce this issue here.
> Key points are:
>
> 1. Existing expired cache entry (i.e. cache updating).
>
> 2. Client abort before nginx was able to receive response header
> from upstream.
>
> 3. Non-cacheable response from upstream.
>
> I'll take a look how to properly fix this.
Please try the attached patch.
Maxim Dounin
-------------- next part --------------
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1308884310 -14400
# Node ID b1a9c139a443797a16e039bdf091b9889fcc8d88
# Parent 1c167244d2fdb064c159012c50a7ae3fd1ed254a
Cache: fix another "stalled cache updating" alert.
The one reported at [1] happens if client closes prematurely connection
before response header was got from upstream and response isn't cacheable.
As such situations are expected to happen on other errors too, teach
ngx_http_upstream_finalize_request() to free cache in such situations.
This is consistent with behaviour for cacheable responses.
[1] http://www.nginx.org/pipermail/nginx/2011-June/027522.html
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2031,15 +2031,6 @@ ngx_http_upstream_send_response(ngx_http
c->error = 1;
} else {
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
- ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
- }
-
-#endif
-
ngx_http_upstream_finalize_request(r, u, rc);
return;
}
@@ -2991,16 +2982,19 @@ ngx_http_upstream_finalize_request(ngx_h
#if (NGX_HTTP_CACHE)
- if (u->cacheable && r->cache) {
- time_t valid;
-
- if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {
-
- valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);
-
- if (valid) {
- r->cache->valid_sec = ngx_time() + valid;
- r->cache->error = rc;
+ if (r->cache) {
+
+ if (u->cacheable) {
+ time_t valid;
+
+ if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {
+
+ valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);
+
+ if (valid) {
+ r->cache->valid_sec = ngx_time() + valid;
+ r->cache->error = rc;
+ }
}
}
More information about the nginx
mailing list