diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2010-10-14 09:20:01 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2010-10-14 09:20:01 +0000 |
| commit | c5d1790e1d7c04599975ccf8697688d3be99157c (patch) | |
| tree | 4ad2aa0a77b8ce9cee6d0da3f113b0feca75ad3c | |
| parent | 622721a598e272ccea54dba8dda2b89227f0d372 (diff) | |
| download | nginx-c5d1790e1d7c04599975ccf8697688d3be99157c.tar.gz nginx-c5d1790e1d7c04599975ccf8697688d3be99157c.tar.bz2 | |
change order of limit_req lookup result processing
| -rw-r--r-- | src/http/modules/ngx_http_limit_req_module.c | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/src/http/modules/ngx_http_limit_req_module.c b/src/http/modules/ngx_http_limit_req_module.c index db2a0e5ff..718fae8e2 100644 --- a/src/http/modules/ngx_http_limit_req_module.c +++ b/src/http/modules/ngx_http_limit_req_module.c @@ -191,81 +191,78 @@ ngx_http_limit_req_handler(ngx_http_request_t *r) ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "limit_req: %i %ui.%03ui", rc, excess / 1000, excess % 1000); - if (rc == NGX_BUSY) { - ngx_shmtx_unlock(&ctx->shpool->mutex); + if (rc == NGX_DECLINED) { - ngx_log_error(lrcf->limit_log_level, r->connection->log, 0, - "limiting requests, excess: %ui.%03ui by zone \"%V\"", - excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name); + n = offsetof(ngx_rbtree_node_t, color) + + offsetof(ngx_http_limit_req_node_t, data) + + len; - return NGX_HTTP_SERVICE_UNAVAILABLE; - } + node = ngx_slab_alloc_locked(ctx->shpool, n); + if (node == NULL) { - if (rc == NGX_AGAIN) { - ngx_shmtx_unlock(&ctx->shpool->mutex); + ngx_http_limit_req_expire(ctx, 0); - if (lrcf->nodelay) { - return NGX_DECLINED; + node = ngx_slab_alloc_locked(ctx->shpool, n); + if (node == NULL) { + ngx_shmtx_unlock(&ctx->shpool->mutex); + return NGX_HTTP_SERVICE_UNAVAILABLE; + } } - ngx_log_error(lrcf->delay_log_level, r->connection->log, 0, - "delaying request, excess: %ui.%03ui, by zone \"%V\"", - excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name); + lr = (ngx_http_limit_req_node_t *) &node->color; - if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } + node->key = hash; + lr->len = (u_char) len; - r->read_event_handler = ngx_http_test_reading; - r->write_event_handler = ngx_http_limit_req_delay; - ngx_add_timer(r->connection->write, - (ngx_msec_t) excess * 1000 / ctx->rate); + tp = ngx_timeofday(); + lr->last = (ngx_msec_t) (tp->sec * 1000 + tp->msec); - return NGX_AGAIN; - } + lr->excess = 0; + ngx_memcpy(lr->data, vv->data, len); - if (rc == NGX_OK) { - goto done; - } + ngx_rbtree_insert(&ctx->sh->rbtree, node); - /* rc == NGX_DECLINED */ + ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); - n = offsetof(ngx_rbtree_node_t, color) - + offsetof(ngx_http_limit_req_node_t, data) - + len; + ngx_shmtx_unlock(&ctx->shpool->mutex); - node = ngx_slab_alloc_locked(ctx->shpool, n); - if (node == NULL) { + return NGX_DECLINED; + } - ngx_http_limit_req_expire(ctx, 0); + ngx_shmtx_unlock(&ctx->shpool->mutex); - node = ngx_slab_alloc_locked(ctx->shpool, n); - if (node == NULL) { - ngx_shmtx_unlock(&ctx->shpool->mutex); - return NGX_HTTP_SERVICE_UNAVAILABLE; - } + if (rc == NGX_OK) { + return NGX_DECLINED; } - lr = (ngx_http_limit_req_node_t *) &node->color; - - node->key = hash; - lr->len = (u_char) len; + if (rc == NGX_BUSY) { + ngx_log_error(lrcf->limit_log_level, r->connection->log, 0, + "limiting requests, excess: %ui.%03ui by zone \"%V\"", + excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name); - tp = ngx_timeofday(); - lr->last = (ngx_msec_t) (tp->sec * 1000 + tp->msec); + return NGX_HTTP_SERVICE_UNAVAILABLE; + } - lr->excess = 0; - ngx_memcpy(lr->data, vv->data, len); + /* rc == NGX_AGAIN */ - ngx_rbtree_insert(&ctx->sh->rbtree, node); + if (lrcf->nodelay) { + return NGX_DECLINED; + } - ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); + ngx_log_error(lrcf->delay_log_level, r->connection->log, 0, + "delaying request, excess: %ui.%03ui, by zone \"%V\"", + excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name); -done: + if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } - ngx_shmtx_unlock(&ctx->shpool->mutex); + r->read_event_handler = ngx_http_test_reading; + r->write_event_handler = ngx_http_limit_req_delay; + ngx_add_timer(r->connection->write, + (ngx_msec_t) excess * 1000 / ctx->rate); - return NGX_DECLINED; + return NGX_AGAIN; } |
