comparison src/http/ngx_http_upstream.c @ 7949:862f6130d357

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 29 Oct 2021 20:21:54 +0300
parents 65946a191197
children 555533169506 61d0fa67b55e
comparison
equal deleted inserted replaced
7948:a2613fc1bce5 7949:862f6130d357
1509 1509
1510 1510
1511 static void 1511 static void
1512 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) 1512 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
1513 { 1513 {
1514 ngx_int_t rc; 1514 ngx_int_t rc;
1515 ngx_connection_t *c; 1515 ngx_connection_t *c;
1516 ngx_http_core_loc_conf_t *clcf;
1516 1517
1517 r->connection->log->action = "connecting to upstream"; 1518 r->connection->log->action = "connecting to upstream";
1518 1519
1519 if (u->state && u->state->response_time == (ngx_msec_t) -1) { 1520 if (u->state && u->state->response_time == (ngx_msec_t) -1) {
1520 u->state->response_time = ngx_current_msec - u->start_time; 1521 u->state->response_time = ngx_current_msec - u->start_time;
1597 c->read->log = c->log; 1598 c->read->log = c->log;
1598 c->write->log = c->log; 1599 c->write->log = c->log;
1599 1600
1600 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ 1601 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */
1601 1602
1603 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1604
1602 u->writer.out = NULL; 1605 u->writer.out = NULL;
1603 u->writer.last = &u->writer.out; 1606 u->writer.last = &u->writer.out;
1604 u->writer.connection = c; 1607 u->writer.connection = c;
1605 u->writer.limit = 0; 1608 u->writer.limit = clcf->sendfile_max_chunk;
1606 1609
1607 if (u->request_sent) { 1610 if (u->request_sent) {
1608 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { 1611 if (ngx_http_upstream_reinit(r, u) != NGX_OK) {
1609 ngx_http_upstream_finalize_request(r, u, 1612 ngx_http_upstream_finalize_request(r, u,
1610 NGX_HTTP_INTERNAL_SERVER_ERROR); 1613 NGX_HTTP_INTERNAL_SERVER_ERROR);