change order of limit_req lookup result processing
This commit is contained in:
parent
622721a598
commit
c5d1790e1d
@ -191,44 +191,7 @@ 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);
|
||||
|
||||
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);
|
||||
|
||||
return NGX_HTTP_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
if (rc == NGX_AGAIN) {
|
||||
ngx_shmtx_unlock(&ctx->shpool->mutex);
|
||||
|
||||
if (lrcf->nodelay) {
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
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_AGAIN;
|
||||
}
|
||||
|
||||
if (rc == NGX_OK) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* rc == NGX_DECLINED */
|
||||
if (rc == NGX_DECLINED) {
|
||||
|
||||
n = offsetof(ngx_rbtree_node_t, color)
|
||||
+ offsetof(ngx_http_limit_req_node_t, data)
|
||||
@ -261,13 +224,47 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
|
||||
|
||||
ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
|
||||
|
||||
done:
|
||||
|
||||
ngx_shmtx_unlock(&ctx->shpool->mutex);
|
||||
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
ngx_shmtx_unlock(&ctx->shpool->mutex);
|
||||
|
||||
if (rc == NGX_OK) {
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return NGX_HTTP_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
/* rc == NGX_AGAIN */
|
||||
|
||||
if (lrcf->nodelay) {
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
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_AGAIN;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_http_limit_req_delay(ngx_http_request_t *r)
|
||||
|
Loading…
x
Reference in New Issue
Block a user