[nginx] svn commit: r4437 - in branches/stable-1.0: . src/http

mdounin at mdounin.ru mdounin at mdounin.ru
Sun Feb 5 13:34:08 UTC 2012


Author: mdounin
Date: 2012-02-05 13:34:08 +0000 (Sun, 05 Feb 2012)
New Revision: 4437

Log:
Merge of r4339, r4340, r4341:

Cache fixes:

*) Obsolete code removed.

   The ngx_http_cache() and ngx_http_no_cache_set_slot() functions
   were replaced in 0.8.46 and no longer used since then.

*) Handling of cache files with long headers.

   There are two possible situations which can lead to this: response
   was cached with bigger proxy_buffer_size value (and nginx was
   restared since then, i.e. shared memory zone content was lost), or
   due to the race in the cache update code (see [1]) we've end up
   with fcn->body_start from a different response stored in shared
   memory zone.

*) Only complain on long locked entries.

   There have been multiple reports of cases where a real locked entry
   was removed, resulting in a segmentation fault later in a worker
   which locked the entry.  It looks like default inactive timeout isn't
   enough in real life.

   For now just ignore such locked entries, and move them to the top of
   the inactive queue to allow processing of other entries.

[1] http://mailman.nginx.org/pipermail/nginx-devel/2011-September/001287.html


Modified:
   branches/stable-1.0/
   branches/stable-1.0/src/http/ngx_http_file_cache.c


Property changes on: branches/stable-1.0
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk:3960-3974,3977-3987,3991-3996,3998,4000-4018,4020,4023,4025-4027,4034-4065,4073,4077,4086-4090,4094-4102,4106-4108,4113-4114,4129-4137,4143-4144,4147-4158,4177,4179,4182-4184,4186-4187,4189-4205,4207,4209-4210,4212,4217-4223,4227-4232,4235-4237,4265-4268,4270,4274-4276,4278-4280,4282-4284,4294-4295,4298,4300-4309,4313,4315,4320-4321,4326-4327,4335-4336,4338,4342-4343,4377
   + /trunk:3960-3974,3977-3987,3991-3996,3998,4000-4018,4020,4023,4025-4027,4034-4065,4073,4077,4086-4090,4094-4102,4106-4108,4113-4114,4129-4137,4143-4144,4147-4158,4177,4179,4182-4184,4186-4187,4189-4205,4207,4209-4210,4212,4217-4223,4227-4232,4235-4237,4265-4268,4270,4274-4276,4278-4280,4282-4284,4294-4295,4298,4300-4309,4313,4315,4320-4321,4326-4327,4335-4336,4338-4343,4377

Modified: branches/stable-1.0/src/http/ngx_http_file_cache.c
===================================================================
--- branches/stable-1.0/src/http/ngx_http_file_cache.c	2012-02-05 12:46:20 UTC (rev 4436)
+++ branches/stable-1.0/src/http/ngx_http_file_cache.c	2012-02-05 13:34:08 UTC (rev 4437)
@@ -387,6 +387,13 @@
         return NGX_DECLINED;
     }
 
+    if (h->body_start > c->body_start) {
+        ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
+                      "cache file \"%s\" has too long header",
+                      c->file.name.data);
+        return NGX_DECLINED;
+    }
+
     c->buf->last += n;
 
     c->valid_sec = h->valid_sec;
@@ -1107,12 +1114,12 @@
         /*
          * abnormally exited workers may leave locked cache entries,
          * and although it may be safe to remove them completely,
-         * we prefer to remove them from inactive queue and rbtree
-         * only, and to allow other leaks
+         * we prefer to just move them to the top of the inactive queue
          */
 
         ngx_queue_remove(q);
-        ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
+        fcn->expire = ngx_time() + cache->inactive;
+        ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
 
         ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
                       "ignore long locked inactive cache entry %*s, count:%d",
@@ -1710,69 +1717,3 @@
 
     return NGX_CONF_OK;
 }
-
-
-ngx_int_t
-ngx_http_cache(ngx_http_request_t *r, ngx_array_t *no_cache)
-{
-    ngx_str_t                  val;
-    ngx_uint_t                 i;
-    ngx_http_complex_value_t  *cv;
-
-    cv = no_cache->elts;
-
-    for (i = 0; i < no_cache->nelts; i++) {
-        if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) {
-            return NGX_ERROR;
-        }
-
-        if (val.len && val.data[0] != '0') {
-            return NGX_DECLINED;
-        }
-    }
-
-    return NGX_OK;
-}
-
-
-char *
-ngx_http_no_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
-    char  *p = conf;
-
-    ngx_str_t                          *value;
-    ngx_uint_t                          i;
-    ngx_array_t                       **a;
-    ngx_http_complex_value_t           *cv;
-    ngx_http_compile_complex_value_t    ccv;
-
-    a = (ngx_array_t **) (p + cmd->offset);
-
-    if (*a == NGX_CONF_UNSET_PTR) {
-        *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_complex_value_t));
-        if (*a == NULL) {
-            return NGX_CONF_ERROR;
-        }
-    }
-
-    value = cf->args->elts;
-
-    for (i = 1; i < cf->args->nelts; i++) {
-        cv = ngx_array_push(*a);
-        if (cv == NULL) {
-            return NGX_CONF_ERROR;
-        }
-
-        ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
-
-        ccv.cf = cf;
-        ccv.value = &value[i];
-        ccv.complex_value = cv;
-
-        if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
-            return NGX_CONF_ERROR;
-        }
-    }
-
-    return NGX_CONF_OK;
-}



More information about the nginx-devel mailing list