<div dir="ltr"># HG changeset patch<br># User Sangdeuk Kwon <<a href="mailto:sangdeuk.kwon@quantil.com">sangdeuk.kwon@quantil.com</a>><br># Date 1571119628 -32400<br>#      Tue Oct 15 15:07:08 2019 +0900<br># Node ID a484d65af8cefef5d6501872a6b72a0623fd9af4<br># Parent  6208c5418c88ce8ecc656b40704a752cb7c7648a<br>nginx cannot respond when big response header with proxy_buffering is off and limit_rate is set.<br><br>If proxy_buffering is off and limit_rate is 1M,<br>nginx cannot respond when response header is over 1k.<br><br>currently, nginx disable limit_rate before sending body.<br>It should be disabled before sending header.<br><br>http {<br>    server {<br>        listen       8100;<br>        server_name  localhost;<br><br>        limit_rate 1M;<br><br>        location / {<br>            proxy_buffering off;<br>            proxy_pass <a href="http://127.0.0.1:8000">http://127.0.0.1:8000</a>;<br>        }<br>    }<br><div>    server {<br>        listen       8000;<br>        server_name  localhost;<br><br>        location / {<br>            return 200 "test\n";<br><br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_000 "000";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_001 "001";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_002 "002";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_003 "003";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_004 "004";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_005 "005";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_006 "006";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_007 "007";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_008 "008";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_009 "009";<br><br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_010 "010";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_011 "011";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_012 "012";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_013 "013";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_014 "014";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_015 "015";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_016 "016";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_017 "017";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_018 "018";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_019 "019";<br><br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_020 "020";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_021 "021";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_022 "022";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_023 "023";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_024 "024";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_025 "025";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_026 "026";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_027 "027";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_028 "028";<br>            add_header Server_flag_C_policy_R-Location_flag_S_policy_029 "029";<br>        }<br>    }<br>}<br><br></div><div>diff -r 6208c5418c88 -r a484d65af8ce src/http/ngx_http_upstream.c<br>--- a/src/http/ngx_http_upstream.c  Tue Oct 08 21:56:14 2019 +0300<br>+++ b/src/http/ngx_http_upstream.c  Tue Oct 15 15:07:08 2019 +0900<br>@@ -2905,6 +2905,11 @@<br>     ngx_connection_t          *c;<br>     ngx_http_core_loc_conf_t  *clcf;<br><br>+    if (!u->buffering) {<br>+        r->limit_rate = 0;<br>+        r->limit_rate_set = 1;<br>+    }<br>+<br>     rc = ngx_http_send_header(r);<br><br>     if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) {<br>@@ -2975,9 +2980,6 @@<br>         r->write_event_handler =<br>                              ngx_http_upstream_process_non_buffered_downstream;<br><br>-        r->limit_rate = 0;<br>-        r->limit_rate_set = 1;<br>-<br>         if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {<br>             ngx_http_upstream_finalize_request(r, u, NGX_ERROR);<br>             return;<br><br></div></div>