Mercurial > hg > nginx
comparison src/http/v2/ngx_http_v2.c @ 7773:b64f553b1291
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 11 Feb 2021 21:52:24 +0300 |
parents | f790816a0e87 |
children | 827202ca1269 |
comparison
equal
deleted
inserted
replaced
7772:f790816a0e87 | 7773:b64f553b1291 |
---|---|
323 c->data = h2c; | 323 c->data = h2c; |
324 | 324 |
325 rev->handler = ngx_http_v2_read_handler; | 325 rev->handler = ngx_http_v2_read_handler; |
326 c->write->handler = ngx_http_v2_write_handler; | 326 c->write->handler = ngx_http_v2_write_handler; |
327 | 327 |
328 if (c->read->timer_set) { | |
329 ngx_del_timer(c->read); | |
330 } | |
331 | |
328 c->idle = 1; | 332 c->idle = 1; |
329 ngx_reusable_connection(c, 0); | 333 ngx_reusable_connection(c, 0); |
330 | 334 |
331 ngx_http_v2_read_handler(rev); | 335 ngx_http_v2_read_handler(rev); |
332 } | 336 } |
452 ngx_http_v2_finalize_connection(h2c, 0); | 456 ngx_http_v2_finalize_connection(h2c, 0); |
453 return; | 457 return; |
454 } | 458 } |
455 | 459 |
456 h2c->blocked = 0; | 460 h2c->blocked = 0; |
457 | |
458 if (h2c->processing || h2c->pushing) { | |
459 if (rev->timer_set) { | |
460 ngx_del_timer(rev); | |
461 } | |
462 | |
463 return; | |
464 } | |
465 | 461 |
466 ngx_http_v2_handle_connection(h2c); | 462 ngx_http_v2_handle_connection(h2c); |
467 } | 463 } |
468 | 464 |
469 | 465 |
636 ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c) | 632 ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c) |
637 { | 633 { |
638 ngx_int_t rc; | 634 ngx_int_t rc; |
639 ngx_connection_t *c; | 635 ngx_connection_t *c; |
640 ngx_http_core_loc_conf_t *clcf; | 636 ngx_http_core_loc_conf_t *clcf; |
641 ngx_http_core_srv_conf_t *cscf; | |
642 | 637 |
643 if (h2c->last_out || h2c->processing || h2c->pushing) { | 638 if (h2c->last_out || h2c->processing || h2c->pushing) { |
644 return; | 639 return; |
645 } | 640 } |
646 | 641 |
673 if (h2c->goaway) { | 668 if (h2c->goaway) { |
674 ngx_http_v2_lingering_close(c); | 669 ngx_http_v2_lingering_close(c); |
675 return; | 670 return; |
676 } | 671 } |
677 | 672 |
673 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, | |
674 ngx_http_core_module); | |
675 | |
676 if (!c->read->timer_set) { | |
677 ngx_add_timer(c->read, clcf->keepalive_timeout); | |
678 } | |
679 | |
678 ngx_reusable_connection(c, 1); | 680 ngx_reusable_connection(c, 1); |
679 | 681 |
680 if (h2c->state.incomplete) { | 682 if (h2c->state.incomplete) { |
681 if (!c->read->timer_set) { | |
682 cscf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, | |
683 ngx_http_core_module); | |
684 ngx_add_timer(c->read, cscf->client_header_timeout); | |
685 } | |
686 | |
687 return; | 683 return; |
688 } | 684 } |
689 | 685 |
690 ngx_destroy_pool(h2c->pool); | 686 ngx_destroy_pool(h2c->pool); |
691 | 687 |
706 c->read->handler = ngx_http_v2_idle_handler; | 702 c->read->handler = ngx_http_v2_idle_handler; |
707 | 703 |
708 if (c->write->timer_set) { | 704 if (c->write->timer_set) { |
709 ngx_del_timer(c->write); | 705 ngx_del_timer(c->write); |
710 } | 706 } |
711 | |
712 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, | |
713 ngx_http_core_module); | |
714 | |
715 ngx_add_timer(c->read, clcf->keepalive_timeout); | |
716 } | 707 } |
717 | 708 |
718 | 709 |
719 static void | 710 static void |
720 ngx_http_v2_lingering_close(ngx_connection_t *c) | 711 ngx_http_v2_lingering_close(ngx_connection_t *c) |
3295 } else { | 3286 } else { |
3296 h2c->processing++; | 3287 h2c->processing++; |
3297 } | 3288 } |
3298 | 3289 |
3299 h2c->priority_limit += h2scf->concurrent_streams; | 3290 h2c->priority_limit += h2scf->concurrent_streams; |
3291 | |
3292 if (h2c->connection->read->timer_set) { | |
3293 ngx_del_timer(h2c->connection->read); | |
3294 } | |
3300 | 3295 |
3301 return stream; | 3296 return stream; |
3302 } | 3297 } |
3303 | 3298 |
3304 | 3299 |
4707 } | 4702 } |
4708 | 4703 |
4709 c->destroyed = 0; | 4704 c->destroyed = 0; |
4710 ngx_reusable_connection(c, 0); | 4705 ngx_reusable_connection(c, 0); |
4711 | 4706 |
4712 if (c->read->timer_set) { | |
4713 ngx_del_timer(c->read); | |
4714 } | |
4715 | |
4716 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, | 4707 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, |
4717 ngx_http_v2_module); | 4708 ngx_http_v2_module); |
4718 | 4709 |
4719 h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log); | 4710 h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log); |
4720 if (h2c->pool == NULL) { | 4711 if (h2c->pool == NULL) { |