summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2021-02-11 21:52:24 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2021-02-11 21:52:24 +0300
commit94567a8f849c02c70ee7f51307fa0372c94c925b (patch)
treeff6b99f8ff831355f0a7d6cc3109d3da5e6ba1af
parent49ab3312448495f0ee8e00143a29624dde46ef5c (diff)
downloadnginx-94567a8f849c02c70ee7f51307fa0372c94c925b.tar.gz
nginx-94567a8f849c02c70ee7f51307fa0372c94c925b.tar.bz2
HTTP/2: keepalive_timeout now armed once between requests.
Previously, PINGs and other frames extended possible keepalive time, making it possible to keep an open HTTP/2 connection for a long time. Now the connection is always closed as long as keepalive_timeout expires, similarly to how it happens in HTTP/1.x. Note that as a part of this change, incomplete frames are no longer trigger a separate timeout, so http2_recv_timeout (replaced by client_header_timeout in previous patches) is essentially cancelled. The client_header_timeout is, however, used for SSL handshake and while reading HEADERS frames.
-rw-r--r--src/http/v2/ngx_http_v2.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
index 071fadb59..e57c65cbb 100644
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -325,6 +325,10 @@ ngx_http_v2_init(ngx_event_t *rev)
rev->handler = ngx_http_v2_read_handler;
c->write->handler = ngx_http_v2_write_handler;
+ if (c->read->timer_set) {
+ ngx_del_timer(c->read);
+ }
+
c->idle = 1;
ngx_reusable_connection(c, 0);
@@ -455,14 +459,6 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
h2c->blocked = 0;
- if (h2c->processing || h2c->pushing) {
- if (rev->timer_set) {
- ngx_del_timer(rev);
- }
-
- return;
- }
-
ngx_http_v2_handle_connection(h2c);
}
@@ -638,7 +634,6 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
ngx_int_t rc;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;
- ngx_http_core_srv_conf_t *cscf;
if (h2c->last_out || h2c->processing || h2c->pushing) {
return;
@@ -675,15 +670,16 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
return;
}
+ clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
+ ngx_http_core_module);
+
+ if (!c->read->timer_set) {
+ ngx_add_timer(c->read, clcf->keepalive_timeout);
+ }
+
ngx_reusable_connection(c, 1);
if (h2c->state.incomplete) {
- if (!c->read->timer_set) {
- cscf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
- ngx_add_timer(c->read, cscf->client_header_timeout);
- }
-
return;
}
@@ -708,11 +704,6 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
if (c->write->timer_set) {
ngx_del_timer(c->write);
}
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- ngx_add_timer(c->read, clcf->keepalive_timeout);
}
@@ -3298,6 +3289,10 @@ ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push)
h2c->priority_limit += h2scf->concurrent_streams;
+ if (h2c->connection->read->timer_set) {
+ ngx_del_timer(h2c->connection->read);
+ }
+
return stream;
}
@@ -4709,10 +4704,6 @@ ngx_http_v2_idle_handler(ngx_event_t *rev)
c->destroyed = 0;
ngx_reusable_connection(c, 0);
- if (c->read->timer_set) {
- ngx_del_timer(c->read);
- }
-
h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
ngx_http_v2_module);