Mercurial > hg > nginx-quic
comparison src/http/v2/ngx_http_v2_filter_module.c @ 6412:4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Previously, there were only three timeouts used globally for the whole HTTP/2
connection:
1. Idle timeout for inactivity when there are no streams in processing
(the "http2_idle_timeout" directive);
2. Receive timeout for incomplete frames when there are no streams in
processing (the "http2_recv_timeout" directive);
3. Send timeout when there are frames waiting in the output queue
(the "send_timeout" directive on a server level).
Reaching one of these timeouts leads to HTTP/2 connection close.
This left a number of scenarios when a connection can get stuck without any
processing and timeouts:
1. A client has sent the headers block partially so nginx starts processing
a new stream but cannot continue without the rest of HEADERS and/or
CONTINUATION frames;
2. When nginx waits for the request body;
3. All streams are stuck on exhausted connection or stream windows.
The first idea that was rejected was to detect when the whole connection
gets stuck because of these situations and set the global receive timeout.
The disadvantage of such approach would be inconsistent behaviour in some
typical use cases. For example, if a user never replies to the browser's
question about where to save the downloaded file, the stream will be
eventually closed by a timeout. On the other hand, this will not happen
if there's some activity in other concurrent streams.
Now almost all the request timeouts work like in HTTP/1.x connections, so
the "client_header_timeout", "client_body_timeout", and "send_timeout" are
respected. These timeouts close the request.
The global timeouts work as before.
Previously, the c->write->delayed flag was abused to avoid setting timeouts on
stream events. Now, the "active" and "ready" flags are manipulated instead to
control the processing of individual streams.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 24 Feb 2016 15:58:07 +0300 |
parents | 6812ca9a8002 |
children | cf3e75cfa951 |
comparison
equal
deleted
inserted
replaced
6411:8ec349bb60b2 | 6412:4ba91a4c66a3 |
---|---|
797 } | 797 } |
798 | 798 |
799 if (in == NULL) { | 799 if (in == NULL) { |
800 | 800 |
801 if (stream->queued) { | 801 if (stream->queued) { |
802 fc->write->delayed = 1; | 802 fc->write->active = 1; |
803 fc->write->ready = 0; | |
804 | |
803 } else { | 805 } else { |
804 fc->buffered &= ~NGX_HTTP_V2_BUFFERED; | 806 fc->buffered &= ~NGX_HTTP_V2_BUFFERED; |
805 } | 807 } |
806 | 808 |
807 return NULL; | 809 return NULL; |
808 } | 810 } |
809 | 811 |
810 h2c = stream->connection; | 812 h2c = stream->connection; |
811 | 813 |
812 if (size && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) { | 814 if (size && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) { |
813 fc->write->delayed = 1; | 815 fc->write->active = 1; |
816 fc->write->ready = 0; | |
814 return in; | 817 return in; |
815 } | 818 } |
816 | 819 |
817 if (in->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) { | 820 if (in->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) { |
818 cl = ngx_alloc_chain_link(r->pool); | 821 cl = ngx_alloc_chain_link(r->pool); |
945 if (ngx_http_v2_filter_send(fc, stream) == NGX_ERROR) { | 948 if (ngx_http_v2_filter_send(fc, stream) == NGX_ERROR) { |
946 return NGX_CHAIN_ERROR; | 949 return NGX_CHAIN_ERROR; |
947 } | 950 } |
948 | 951 |
949 if (in && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) { | 952 if (in && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) { |
950 fc->write->delayed = 1; | 953 fc->write->active = 1; |
954 fc->write->ready = 0; | |
951 } | 955 } |
952 | 956 |
953 return in; | 957 return in; |
954 } | 958 } |
955 | 959 |
1076 | 1080 |
1077 stream->blocked = 0; | 1081 stream->blocked = 0; |
1078 | 1082 |
1079 if (stream->queued) { | 1083 if (stream->queued) { |
1080 fc->buffered |= NGX_HTTP_V2_BUFFERED; | 1084 fc->buffered |= NGX_HTTP_V2_BUFFERED; |
1081 fc->write->delayed = 1; | 1085 fc->write->active = 1; |
1086 fc->write->ready = 0; | |
1082 return NGX_AGAIN; | 1087 return NGX_AGAIN; |
1083 } | 1088 } |
1084 | 1089 |
1085 fc->buffered &= ~NGX_HTTP_V2_BUFFERED; | 1090 fc->buffered &= ~NGX_HTTP_V2_BUFFERED; |
1086 | 1091 |
1314 return; | 1319 return; |
1315 } | 1320 } |
1316 | 1321 |
1317 wev = stream->request->connection->write; | 1322 wev = stream->request->connection->write; |
1318 | 1323 |
1319 /* | 1324 if (!wev->delayed) { |
1320 * This timer can only be set if the stream was delayed because of rate | |
1321 * limit. In that case the event should be triggered by the timer. | |
1322 */ | |
1323 | |
1324 if (!wev->timer_set) { | |
1325 wev->delayed = 0; | |
1326 | |
1327 stream->handled = 1; | 1325 stream->handled = 1; |
1328 ngx_queue_insert_tail(&h2c->posted, &stream->queue); | 1326 ngx_queue_insert_tail(&h2c->posted, &stream->queue); |
1329 } | 1327 } |
1330 } | 1328 } |
1331 | 1329 |