aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_limit_req_module.c99
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;
}