comparison src/http/v2/ngx_http_v2.c @ 7564:29b2dc731503

HTTP/2: close connection on frames with self-dependency. Don't waste server resources by sending RST_STREAM frames. Instead, reject HEADERS and PRIORITY frames with self-dependency by closing connection with PROTOCOL_ERROR.
author Ruslan Ermilov <ru@nginx.com>
date Tue, 10 Sep 2019 15:33:37 +0300
parents 9f1f9d6e056a
children fd6dcc6f8a49
comparison
equal deleted inserted replaced
7563:a7e8f953408e 7564:29b2dc731503
1105 "%ui, the last was %ui", h2c->state.sid, h2c->last_sid); 1105 "%ui, the last was %ui", h2c->state.sid, h2c->last_sid);
1106 1106
1107 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); 1107 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
1108 } 1108 }
1109 1109
1110 h2c->last_sid = h2c->state.sid;
1111
1112 h2c->state.pool = ngx_create_pool(1024, h2c->connection->log);
1113 if (h2c->state.pool == NULL) {
1114 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
1115 }
1116
1117 if (depend == h2c->state.sid) { 1110 if (depend == h2c->state.sid) {
1118 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, 1111 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
1119 "client sent HEADERS frame for stream %ui " 1112 "client sent HEADERS frame for stream %ui "
1120 "with incorrect dependency", h2c->state.sid); 1113 "with incorrect dependency", h2c->state.sid);
1121 1114
1122 status = NGX_HTTP_V2_PROTOCOL_ERROR; 1115 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
1123 goto rst_stream; 1116 }
1117
1118 h2c->last_sid = h2c->state.sid;
1119
1120 h2c->state.pool = ngx_create_pool(1024, h2c->connection->log);
1121 if (h2c->state.pool == NULL) {
1122 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
1124 } 1123 }
1125 1124
1126 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, 1125 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
1127 ngx_http_v2_module); 1126 ngx_http_v2_module);
1128 1127
1847 if (depend == h2c->state.sid) { 1846 if (depend == h2c->state.sid) {
1848 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, 1847 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
1849 "client sent PRIORITY frame for stream %ui " 1848 "client sent PRIORITY frame for stream %ui "
1850 "with incorrect dependency", h2c->state.sid); 1849 "with incorrect dependency", h2c->state.sid);
1851 1850
1852 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0); 1851 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
1853
1854 if (node && node->stream) {
1855 if (ngx_http_v2_terminate_stream(h2c, node->stream,
1856 NGX_HTTP_V2_PROTOCOL_ERROR)
1857 == NGX_ERROR)
1858 {
1859 return ngx_http_v2_connection_error(h2c,
1860 NGX_HTTP_V2_INTERNAL_ERROR);
1861 }
1862
1863 } else {
1864 if (ngx_http_v2_send_rst_stream(h2c, h2c->state.sid,
1865 NGX_HTTP_V2_PROTOCOL_ERROR)
1866 == NGX_ERROR)
1867 {
1868 return ngx_http_v2_connection_error(h2c,
1869 NGX_HTTP_V2_INTERNAL_ERROR);
1870 }
1871 }
1872
1873 return ngx_http_v2_state_complete(h2c, pos, end);
1874 } 1852 }
1875 1853
1876 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1); 1854 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1);
1877 1855
1878 if (node == NULL) { 1856 if (node == NULL) {