[PATCH] nginx cannot respond when big response header with proxy_buffering is off and limit_rate is set.

Sangdeuk Kwon sangdeuk.kwon at quantil.com
Tue Oct 15 06:11:12 UTC 2019


# HG changeset patch
# User Sangdeuk Kwon <sangdeuk.kwon at quantil.com>
# Date 1571119628 -32400
#      Tue Oct 15 15:07:08 2019 +0900
# Node ID a484d65af8cefef5d6501872a6b72a0623fd9af4
# Parent  6208c5418c88ce8ecc656b40704a752cb7c7648a
nginx cannot respond when big response header with proxy_buffering is off
and limit_rate is set.

If proxy_buffering is off and limit_rate is 1M,
nginx cannot respond when response header is over 1k.

currently, nginx disable limit_rate before sending body.
It should be disabled before sending header.

http {
    server {
        listen       8100;
        server_name  localhost;

        limit_rate 1M;

        location / {
            proxy_buffering off;
            proxy_pass http://127.0.0.1:8000;
        }
    }
    server {
        listen       8000;
        server_name  localhost;

        location / {
            return 200 "test\n";

            add_header Server_flag_C_policy_R-Location_flag_S_policy_000
"000";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_001
"001";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_002
"002";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_003
"003";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_004
"004";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_005
"005";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_006
"006";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_007
"007";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_008
"008";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_009
"009";

            add_header Server_flag_C_policy_R-Location_flag_S_policy_010
"010";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_011
"011";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_012
"012";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_013
"013";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_014
"014";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_015
"015";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_016
"016";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_017
"017";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_018
"018";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_019
"019";

            add_header Server_flag_C_policy_R-Location_flag_S_policy_020
"020";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_021
"021";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_022
"022";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_023
"023";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_024
"024";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_025
"025";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_026
"026";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_027
"027";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_028
"028";
            add_header Server_flag_C_policy_R-Location_flag_S_policy_029
"029";
        }
    }
}

diff -r 6208c5418c88 -r a484d65af8ce src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c  Tue Oct 08 21:56:14 2019 +0300
+++ b/src/http/ngx_http_upstream.c  Tue Oct 15 15:07:08 2019 +0900
@@ -2905,6 +2905,11 @@
     ngx_connection_t          *c;
     ngx_http_core_loc_conf_t  *clcf;

+    if (!u->buffering) {
+        r->limit_rate = 0;
+        r->limit_rate_set = 1;
+    }
+
     rc = ngx_http_send_header(r);

     if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) {
@@ -2975,9 +2980,6 @@
         r->write_event_handler =

ngx_http_upstream_process_non_buffered_downstream;

-        r->limit_rate = 0;
-        r->limit_rate_set = 1;
-
         if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {
             ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
             return;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20191015/167fe17e/attachment.htm>


More information about the nginx-devel mailing list