Mercurial > hg > nginx
changeset 3779:57aecfdcac3d
an excess was logged as 0.000 if requests were limited without delay:
*) use a real excess value instead of non-updated limit_req rbtree node field,
*) move inactivity queue handling inside ngx_http_limit_req_lookup()
since the node is not required outside the lookup function;
the bug has been introduced in r3184
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 13 Oct 2010 20:58:41 +0000 |
parents | d29e8060ca0c |
children | d94d7104f598 |
files | src/http/modules/ngx_http_limit_req_module.c |
diffstat | 1 files changed, 8 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http/modules/ngx_http_limit_req_module.c Tue Oct 12 12:18:39 2010 +0000 +++ b/src/http/modules/ngx_http_limit_req_module.c Wed Oct 13 20:58:41 2010 +0000 @@ -51,7 +51,7 @@ static void ngx_http_limit_req_delay(ngx_http_request_t *r); static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_conf_t *lrcf, - ngx_uint_t hash, u_char *data, size_t len, ngx_http_limit_req_node_t **lrp); + ngx_uint_t hash, u_char *data, size_t len, ngx_uint_t *ep); static void ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, ngx_uint_t n); @@ -186,18 +186,7 @@ ngx_http_limit_req_expire(ctx, 1); - rc = ngx_http_limit_req_lookup(lrcf, hash, vv->data, len, &lr); - - if (lr) { - ngx_queue_remove(&lr->queue); - - ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); - - excess = lr->excess; - - } else { - excess = 0; - } + rc = ngx_http_limit_req_lookup(lrcf, hash, vv->data, len, &excess); ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "limit_req: %i %ui.%03ui", rc, excess / 1000, excess % 1000); @@ -356,7 +345,7 @@ static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_conf_t *lrcf, ngx_uint_t hash, - u_char *data, size_t len, ngx_http_limit_req_node_t **lrp) + u_char *data, size_t len, ngx_uint_t *ep) { ngx_int_t rc, excess; ngx_time_t *tp; @@ -391,6 +380,8 @@ rc = ngx_memn2cmp(data, lr->data, len, (size_t) lr->len); if (rc == 0) { + ngx_queue_remove(&lr->queue); + ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); tp = ngx_timeofday(); @@ -403,16 +394,15 @@ excess = 0; } + *ep = excess; + if ((ngx_uint_t) excess > lrcf->burst) { - *lrp = lr; return NGX_BUSY; } lr->excess = excess; lr->last = now; - *lrp = lr; - if (excess) { return NGX_AGAIN; } @@ -427,7 +417,7 @@ break; } - *lrp = NULL; + *ep = 0; return NGX_DECLINED; }