<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><p style="margin: 0;">Thank you for your reply.</p><p style="margin: 0;"><br></p><div style="margin: 0;">Firstly, we meet the problem. And this patch works for me.</div><div style="margin: 0;"><br></div><div style="margin: 0;">My scenario is after send response body about 10-20MB, we just set:</div><div style="margin: 0;">1. limit_rate = 1KB</div><div style="margin: 0;">2. limit_rate_after = body_bytes_sent</div><div style="margin: 0;">3. proxy_buffering = "on" £šI think this is the key issue£©</div><p style="margin: 0;"><br></p><p style="margin: 0;">At the request begining, we didn't set proxy_buffering = "on" and limit_rate.</p><div style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><p style="margin: 0;"><br></p><pre><br>At 2023-12-27 19:19:01, "Maxim Dounin" <mdounin@mdounin.ru> wrote:
>Hello!
>
>On Wed, Dec 27, 2023 at 10:56:44AM +0800, Jiuzhou Cui wrote:
>
>> Hello!
>> 
>> 
>> # HG changeset patch
>> # User Jiuzhou Cui <cuijiuzhou@alibaba-inc.com>
>> # Date 1703645578 -28800
>> #      Wed Dec 27 10:52:58 2023 +0800
>> # Node ID 474ae07e47272e435d81c0ca9e4867aae35c30ab
>> # Parent  ee40e2b1d0833b46128a357fbc84c6e23be9be07
>> Don't delete timer of write event when it's delayed.
>> 
>> 
>> This will make download speed alway zero when limit_rate in body filter.
>> 
>> 
>> diff -r ee40e2b1d083 -r 474ae07e4727 src/http/ngx_http_upstream.c
>> --- a/src/http/ngx_http_upstream.c      Mon Dec 25 21:15:48 2023 +0400
>> +++ b/src/http/ngx_http_upstream.c      Wed Dec 27 10:52:58 2023 +0800
>> @@ -3787,11 +3787,13 @@
>>          }
>>      }
>> 
>> 
>> -    if (downstream->write->active && !downstream->write->ready) {
>> -        ngx_add_timer(downstream->write, clcf->send_timeout);
>> -
>> -    } else if (downstream->write->timer_set) {
>> -        ngx_del_timer(downstream->write);
>> +    if (!downstream->write->delayed) {
>> +        if (downstream->write->active && !downstream->write->ready) {
>> +            ngx_add_timer(downstream->write, clcf->send_timeout);
>> +
>> +        } else if (downstream->write->timer_set) {
>> +            ngx_del_timer(downstream->write);
>> +        }
>>      }
>> 
>> 
>>      if (upstream->read->eof || upstream->read->error) {
>
>Thank you for the patch.
>
>You are patching the 
>ngx_http_upstream_process_non_buffered_request() function, which 
>is, as can be correctly concluded from the function name, is used 
>for non-buffered proxying.  Non-buffered proxying is specifically 
>designed to return responses as long as they are available, and is 
>not compatible with limit_rate.  Moreover, limit_rate is 
>explicitly disabled in the ngx_http_upstream_send_response() 
>function when the relevant handers are set:
>
>        u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream;
>        r->write_event_handler =
>                             ngx_http_upstream_process_non_buffered_downstream;
>
>        r->limit_rate = 0;
>        r->limit_rate_set = 1;
>
>(https://hg.nginx.org/nginx/file/release-1.25.3/src/http/ngx_http_upstream.c#l3092)
>
>As such, the issue you are trying to fix is not expected to 
>appear.
>
>Could you please clarify the configuration you are seeing the 
>issue with, and steps to reproduce the issue?
>
>-- 
>Maxim Dounin
>http://mdounin.ru/
>_______________________________________________
>nginx-devel mailing list
>nginx-devel@nginx.org
>https://mailman.nginx.org/mailman/listinfo/nginx-devel
</pre></div>