From: Roman Arutyunyan Date: Tue, 17 Nov 2026 19:44:39 +0000 (+0400) Subject: Core: avoid repeating send_chain() when it sent nothing X-Git-Tag: release-1.31.10~1 X-Git-Url: https://git.kaiwu.me/http/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=a12a232e6472b39a53b5e31266846843e142950d;p=nginx.git Core: avoid repeating send_chain() when it sent nothing Previously, ngx_chain_writer() re-posted the write event to continue a capped send whenever output data remained and c->write->ready was still set. This was wrong when c->send_chain() returned without sending anything while the write event still looked ready, notably when SSL_write() returned SSL_ERROR_WANT_READ. The event was then re-posted on every event loop iteration, busy-looping the worker at 100% CPU. The re-post was introduced without a progress check in b3b368184 (1.21.4). A check is now added by requiring that c->send_chain() advanced c->sent. --- diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index eb467e06a..b3a623e1c 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -670,7 +670,7 @@ ngx_chain_writer(void *data, ngx_chain_t *in) { ngx_chain_writer_ctx_t *ctx = data; - off_t size; + off_t size, sent; ngx_chain_t *cl, *ln, *chain; ngx_connection_t *c; @@ -787,6 +787,8 @@ ngx_chain_writer(void *data, ngx_chain_t *in) return NGX_OK; } + sent = c->sent; + chain = c->send_chain(c, ctx->out, ctx->limit); ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, @@ -796,7 +798,7 @@ ngx_chain_writer(void *data, ngx_chain_t *in) return NGX_ERROR; } - if (chain && c->write->ready) { + if (chain && c->write->ready && c->sent != sent) { ngx_post_event(c->write, &ngx_posted_next_events); }