Skip to content

Commit 8737be6

Browse files
feat: add http2 per iteration stream handling limit patch (#82)
1 parent 9c12612 commit 8737be6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff --git src/http/v2/ngx_http_v2.c src/http/v2/ngx_http_v2.c
2+
index 3afa8b638..228b060bf 100644
3+
--- src/http/v2/ngx_http_v2.c
4+
+++ src/http/v2/ngx_http_v2.c
5+
@@ -361,6 +361,7 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
6+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http2 read handler");
7+
8+
h2c->blocked = 1;
9+
+ h2c->new_streams = 0;
10+
11+
if (c->close) {
12+
c->close = 0;
13+
@@ -1321,6 +1322,14 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
14+
goto rst_stream;
15+
}
16+
17+
+ if (h2c->new_streams++ >= 2 * h2scf->concurrent_streams) {
18+
+ ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
19+
+ "client sent too many streams at once");
20+
+
21+
+ status = NGX_HTTP_V2_REFUSED_STREAM;
22+
+ goto rst_stream;
23+
+ }
24+
+
25+
if (!h2c->settings_ack
26+
&& !(h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG)
27+
&& h2scf->preread_size < NGX_HTTP_V2_DEFAULT_WINDOW)
28+
@@ -1386,6 +1395,12 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
29+
30+
rst_stream:
31+
32+
+ if (h2c->refused_streams++ > ngx_max(h2scf->concurrent_streams, 100)) {
33+
+ ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
34+
+ "client sent too many refused streams");
35+
+ return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_NO_ERROR);
36+
+ }
37+
+
38+
if (ngx_http_v2_send_rst_stream(h2c, h2c->state.sid, status) != NGX_OK) {
39+
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
40+
}
41+
diff --git src/http/v2/ngx_http_v2.h src/http/v2/ngx_http_v2.h
42+
index 0eceae3d5..aef40bbb8 100644
43+
--- src/http/v2/ngx_http_v2.h
44+
+++ src/http/v2/ngx_http_v2.h
45+
@@ -124,6 +124,8 @@ struct ngx_http_v2_connection_s {
46+
ngx_uint_t processing;
47+
ngx_uint_t frames;
48+
ngx_uint_t idle;
49+
+ ngx_uint_t new_streams;
50+
+ ngx_uint_t refused_streams;
51+
ngx_uint_t priority_limit;
52+
53+
ngx_uint_t pushing;

0 commit comments

Comments
 (0)