diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2021-10-29 20:21:54 +0300 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2021-10-29 20:21:54 +0300 |
commit | b3b368184b1e3c82da6703e8d7367f38fdc98d1a (patch) | |
tree | 90b050a7621ba3a9595e96a8c5d6b29723752895 | |
parent | 6b0d773fbd95675b64ceaa34aefd60ae92b2a96b (diff) | |
download | nginx-b3b368184b1e3c82da6703e8d7367f38fdc98d1a.tar.gz |
Upstream: sendfile_max_chunk support.
Previously, connections to upstream servers used sendfile() if it was
enabled, but never honored sendfile_max_chunk. This might result
in worker monopolization for a long time if large request bodies
are allowed.
-rw-r--r-- | src/core/ngx_output_chain.c | 4 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.c | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index 5c3dbe872..fd4603b19 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -803,6 +803,10 @@ ngx_chain_writer(void *data, ngx_chain_t *in) return NGX_ERROR; } + if (chain && c->write->ready) { + ngx_post_event(c->write, &ngx_posted_next_events); + } + for (cl = ctx->out; cl && cl != chain; /* void */) { ln = cl; cl = cl->next; diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index daa8d2201..002b3e65d 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -1511,8 +1511,9 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, static void ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) { - ngx_int_t rc; - ngx_connection_t *c; + ngx_int_t rc; + ngx_connection_t *c; + ngx_http_core_loc_conf_t *clcf; r->connection->log->action = "connecting to upstream"; @@ -1599,10 +1600,12 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + u->writer.out = NULL; u->writer.last = &u->writer.out; u->writer.connection = c; - u->writer.limit = 0; + u->writer.limit = clcf->sendfile_max_chunk; if (u->request_sent) { if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |