Opened 8 years ago

Closed 7 years ago

Last modified 6 years ago

#1102 closed defect (fixed)

keepalive_requests is not supported for HTTP/2 connections

Reported by: hwyuan@… Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.11.x
Keywords: keepalive_requests, HTTP2 Cc:
uname -a: 3.16.0-60-generic 80~14.04.1-Ubuntu
nginx -V: built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
built with OpenSSL 1.0.2j 26 Sep 2016
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_v2_module --with-openssl=/PATH/TO/OPENSSL/openssl-1.0.2j

Description

Looks like the limit of keepalive_requests is not supported for HTTP/2 connections.

The following are a server config that can reproduce the issue and the access logs with HTTP/2 turned on and off.

http {
    log_format   main '$remote_addr - $remote_user [$time_local]  $status\t'
                      '$connection\t'
                      '$connection_requests\t';

    access_log   /PATH/TO/LOGS/access.log  main;

    server {
        listen 127.0.0.1:8080 ssl http2;

        ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
        ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

        keepalive_requests 10;

        location / {
            return 200;
        }
    }

}

Even though keepalive_requests is set to 10, when keeps visiting https://127.0.0.1:8080 from a browser, the number of connection_requests would just keeps increasing.

127.0.0.1 - - [11/Oct/2016:21:16:04 +0000]  200	3	1
127.0.0.1 - - [11/Oct/2016:21:16:05 +0000]  200	3	2
127.0.0.1 - - [11/Oct/2016:21:16:05 +0000]  200	3	3
127.0.0.1 - - [11/Oct/2016:21:16:05 +0000]  200	3	4
127.0.0.1 - - [11/Oct/2016:21:16:06 +0000]  200	3	5
127.0.0.1 - - [11/Oct/2016:21:16:06 +0000]  200	3	6
127.0.0.1 - - [11/Oct/2016:21:16:06 +0000]  200	3	7
127.0.0.1 - - [11/Oct/2016:21:16:06 +0000]  200	3	8
127.0.0.1 - - [11/Oct/2016:21:16:06 +0000]  200	3	9
127.0.0.1 - - [11/Oct/2016:21:16:07 +0000]  200	3	10
127.0.0.1 - - [11/Oct/2016:21:16:07 +0000]  200	3	11 <--- keeps increasing
127.0.0.1 - - [11/Oct/2016:21:16:07 +0000]  200	3	12
127.0.0.1 - - [11/Oct/2016:21:16:08 +0000]  200	3	13
127.0.0.1 - - [11/Oct/2016:21:16:08 +0000]  200	3	14
127.0.0.1 - - [11/Oct/2016:21:16:08 +0000]  200	3	15
127.0.0.1 - - [11/Oct/2016:21:16:08 +0000]  200	3	16
127.0.0.1 - - [11/Oct/2016:21:16:08 +0000]  200	3	17
127.0.0.1 - - [11/Oct/2016:21:16:09 +0000]  200	3	18
127.0.0.1 - - [11/Oct/2016:21:16:09 +0000]  200	3	19
127.0.0.1 - - [11/Oct/2016:21:16:09 +0000]  200	3	20
127.0.0.1 - - [11/Oct/2016:21:16:09 +0000]  200	3	21
127.0.0.1 - - [11/Oct/2016:21:16:09 +0000]  200	3	22
127.0.0.1 - - [11/Oct/2016:21:16:10 +0000]  200	3	23
127.0.0.1 - - [11/Oct/2016:21:16:10 +0000]  200	3	24

But for HTTP/1.1, the keepalive_requests directive is respected, and a new connection will be created once the current one has >= 10 requests.

127.0.0.1 - - [11/Oct/2016:21:13:23 +0000]  200	3	1
127.0.0.1 - - [11/Oct/2016:21:13:28 +0000]  200	3	2
127.0.0.1 - - [11/Oct/2016:21:13:28 +0000]  200	3	3
127.0.0.1 - - [11/Oct/2016:21:13:29 +0000]  200	3	4
127.0.0.1 - - [11/Oct/2016:21:13:29 +0000]  200	3	5
127.0.0.1 - - [11/Oct/2016:21:13:29 +0000]  200	3	6
127.0.0.1 - - [11/Oct/2016:21:13:29 +0000]  200	3	7
127.0.0.1 - - [11/Oct/2016:21:13:30 +0000]  200	3	8
127.0.0.1 - - [11/Oct/2016:21:13:30 +0000]  200	3	9
127.0.0.1 - - [11/Oct/2016:21:13:30 +0000]  200	3	10
127.0.0.1 - - [11/Oct/2016:21:13:31 +0000]  200	6	1 <--- new connection
127.0.0.1 - - [11/Oct/2016:21:13:31 +0000]  200	6	2
127.0.0.1 - - [11/Oct/2016:21:13:31 +0000]  200	6	3
127.0.0.1 - - [11/Oct/2016:21:13:32 +0000]  200	6	4
127.0.0.1 - - [11/Oct/2016:21:13:32 +0000]  200	6	5
127.0.0.1 - - [11/Oct/2016:21:13:32 +0000]  200	6	6
127.0.0.1 - - [11/Oct/2016:21:13:33 +0000]  200	6	7
127.0.0.1 - - [11/Oct/2016:21:13:33 +0000]  200	6	8
127.0.0.1 - - [11/Oct/2016:21:13:33 +0000]  200	6	9
127.0.0.1 - - [11/Oct/2016:21:13:34 +0000]  200	6	10 
127.0.0.1 - - [11/Oct/2016:21:13:34 +0000]  200	9	1 <--- new connection

Change History (4)

comment:1 by Alexey Ivanov, 7 years ago

This should be fixed by: http://hg.nginx.org/nginx/rev/9027991e2f37

changeset: 6783:9027991e2f37
user:      Valentin Bartenev <vbart@nginx.com>
date:      Mon Oct 31 16:33:02 2016 +0300
description:
HTTP/2: limited maximum number of requests in connection.

comment:2 by Valentin V. Bartenev, 7 years ago

Resolution: fixed
Status: newclosed

The keepalive_requests directive isn't supposed to work with HTTP/2. There is no such thing as keep-alive in HTTP/2 in terms of HTTP/1.x protocol. Even the directive's default value (100) isn't suitable for HTTP/2 if we try to use it the same way: limit the total number of requests in HTTP/2 connection.

But I understand the problem you're trying to solve. For that reason the new directive http2_max_requests has been introduced in nginx 1.11.6. Please check the documentation.

comment:3 by Alexey Ivanov, 7 years ago

Seems like most modern browsers are failing to properly handle GOAWAY, ones that are able to handle it gracefully, fail to retry streams above last_accepted_stream_id.

Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1050329
Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=681477

Test case for your favorite browser: https://d889ne7b3rd4a.cloudfront.net/cloudfront-http2-test4/test2.html

comment:4 by nh2@…, 6 years ago

I believe the browsers are not at fault, the way nginx is closing the connection is the problem.

See https://trac.nginx.org/nginx/ticket/1250#comment:4 for more details.


But I understand the problem you're trying to solve.

Could you let me know what this problem was?

What is the motivation behind limiting an HTTP2 connection to a fixed maximum number of http2_max_requests?

Note: See TracTickets for help on using tickets.