Thanks Another question, can I remove line 666 to 675 in ngx_http_upstream_init_request? Because the state will be created in ngx_http_upstream_connect.
546 static void 547 ngx_http_upstream_init_request(ngx_http_request_t *r) 548 { 549 ngx_str_t *host; 550 ngx_uint_t i; 551 ngx_resolver_ctx_t *ctx, temp; 552 ngx_http_cleanup_t *cln; 553 ngx_http_upstream_t *u; 554 ngx_http_core_loc_conf_t *clcf; 555 ngx_http_upstream_srv_conf_t *uscf, **uscfp; 556 ngx_http_upstream_main_conf_t *umcf; 657 if (r->upstream_states == NULL) { 658 659 r->upstream_states = ngx_array_create(r->pool, 1, 660 sizeof(ngx_http_upstream_state_t)); 661 if (r->upstream_states == NULL) { 662 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 663 return; 664 } 665 - 666 } else { - 667 - 668 u->state = ngx_array_push(r->upstream_states); - 669 if (u->state == NULL) { - 670 ngx_http_upstream_finalize_request(r, u, - 671 NGX_HTTP_INTERNAL_SERVER_ERROR); - 672 return; - 673 } -674 -675 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); 676 } On 2023/4/20, 10:58 PM, "nginx-devel on behalf of Maxim Dounin" <nginx-devel-boun...@nginx.org <mailto:nginx-devel-boun...@nginx.org> on behalf of mdou...@mdounin.ru <mailto:mdou...@mdounin.ru>> wrote: Hello! On Thu, Apr 20, 2023 at 02:24:53PM +0000, meng lynch wrote: > Hello guys, > > Should the code from line 1517 to 1519 be removed? Because u->state is > reallocated in line 1521. > > 1509 static void > 1510 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) > 1511 { > 1512 ngx_int_t rc; > 1513 ngx_connection_t *c; > 1514 > 1515 r->connection->log->action = "connecting to upstream"; > 1516 > - 1517 if (u->state && u->state->response_time == (ngx_msec_t) -1) { > - 1518 u->state->response_time = ngx_current_msec - u->start_time; > - 1519 } > 1520 > 1521 u->state = ngx_array_push(r->upstream_states); > 1522 if (u->state == NULL) { > 1523 ngx_http_upstream_finalize_request(r, u, > 1524 NGX_HTTP_INTERNAL_SERVER_ERROR); > 1525 return; > 1526 } > In line 1521, the new state is allocated - the one which will be used for the connection started with this ngx_http_upstream_connect() call. The code in lines 1517..1519 finalizes the previous state, the one created by the previous connection (if any). So no, this code shouldn't be removed, it is actually used. -- Maxim Dounin http://mdounin.ru/ <http://mdounin.ru/> _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org <mailto:nginx-devel@nginx.org> https://mailman.nginx.org/mailman/listinfo/nginx-devel <https://mailman.nginx.org/mailman/listinfo/nginx-devel> _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel