Skip to content

Commit

Permalink
HTTP/2: limited number of PRIORITY frames.
Browse files Browse the repository at this point in the history
Fixed excessive CPU usage caused by a peer that continuously shuffles
priority of streams.  Fix is to limit the number of PRIORITY frames.
  • Loading branch information
mdocguard committed Aug 13, 2019
1 parent a987f81 commit 5ae7269
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/http/v2/ngx_http_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ ngx_http_v2_init(ngx_event_t *rev)
h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);

h2c->concurrent_pushes = h2scf->concurrent_pushes;
h2c->priority_limit = h2scf->concurrent_streams;

h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);
if (h2c->pool == NULL) {
Expand Down Expand Up @@ -1804,6 +1805,13 @@ ngx_http_v2_state_priority(ngx_http_v2_connection_t *h2c, u_char *pos,
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
}

if (--h2c->priority_limit == 0) {
ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
"client sent too many PRIORITY frames");

return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
}

if (end - pos < NGX_HTTP_V2_PRIORITY_SIZE) {
return ngx_http_v2_state_save(h2c, pos, end,
ngx_http_v2_state_priority);
Expand Down Expand Up @@ -3120,6 +3128,8 @@ ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push)
h2c->processing++;
}

h2c->priority_limit += h2scf->concurrent_streams;

return stream;
}

Expand Down
1 change: 1 addition & 0 deletions src/http/v2/ngx_http_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct ngx_http_v2_connection_s {
ngx_uint_t processing;
ngx_uint_t frames;
ngx_uint_t idle;
ngx_uint_t priority_limit;

ngx_uint_t pushing;
ngx_uint_t concurrent_pushes;
Expand Down

0 comments on commit 5ae7269

Please sign in to comment.