Mercurial > hg > nginx-quic
comparison src/http/ngx_http_upstream.c @ 6466:984687f25998
Upstream: cached connections now tested against next_upstream.
Much like normal connections, cached connections are now tested against
u->conf->next_upstream, and u->state->status is now always set.
This allows to disable additional tries even with upstream keepalive
by using "proxy_next_upstream off".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 28 Mar 2016 19:49:52 +0300 |
parents | fc72784b1f52 |
children | 91c8d990fb45 |
comparison
equal
deleted
inserted
replaced
6465:9fd68d5009e3 | 6466:984687f25998 |
---|---|
3945 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { | 3945 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
3946 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | 3946 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, |
3947 "upstream timed out"); | 3947 "upstream timed out"); |
3948 } | 3948 } |
3949 | 3949 |
3950 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR | 3950 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) { |
3951 && (!u->request_sent || !r->request_body_no_buffering)) | |
3952 { | |
3953 status = 0; | |
3954 | |
3955 /* TODO: inform balancer instead */ | 3951 /* TODO: inform balancer instead */ |
3956 | |
3957 u->peer.tries++; | 3952 u->peer.tries++; |
3958 | 3953 } |
3959 } else { | 3954 |
3960 switch (ft_type) { | 3955 switch (ft_type) { |
3961 | 3956 |
3962 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: | 3957 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: |
3963 status = NGX_HTTP_GATEWAY_TIME_OUT; | 3958 status = NGX_HTTP_GATEWAY_TIME_OUT; |
3964 break; | 3959 break; |
3965 | 3960 |
3966 case NGX_HTTP_UPSTREAM_FT_HTTP_500: | 3961 case NGX_HTTP_UPSTREAM_FT_HTTP_500: |
3967 status = NGX_HTTP_INTERNAL_SERVER_ERROR; | 3962 status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
3968 break; | 3963 break; |
3969 | 3964 |
3970 case NGX_HTTP_UPSTREAM_FT_HTTP_403: | 3965 case NGX_HTTP_UPSTREAM_FT_HTTP_403: |
3971 status = NGX_HTTP_FORBIDDEN; | 3966 status = NGX_HTTP_FORBIDDEN; |
3972 break; | 3967 break; |
3973 | 3968 |
3974 case NGX_HTTP_UPSTREAM_FT_HTTP_404: | 3969 case NGX_HTTP_UPSTREAM_FT_HTTP_404: |
3975 status = NGX_HTTP_NOT_FOUND; | 3970 status = NGX_HTTP_NOT_FOUND; |
3976 break; | 3971 break; |
3977 | 3972 |
3978 /* | 3973 /* |
3979 * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING | 3974 * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING |
3980 * never reach here | 3975 * never reach here |
3981 */ | 3976 */ |
3982 | 3977 |
3983 default: | 3978 default: |
3984 status = NGX_HTTP_BAD_GATEWAY; | 3979 status = NGX_HTTP_BAD_GATEWAY; |
3985 } | |
3986 } | 3980 } |
3987 | 3981 |
3988 if (r->connection->error) { | 3982 if (r->connection->error) { |
3989 ngx_http_upstream_finalize_request(r, u, | 3983 ngx_http_upstream_finalize_request(r, u, |
3990 NGX_HTTP_CLIENT_CLOSED_REQUEST); | 3984 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
3991 return; | 3985 return; |
3992 } | 3986 } |
3993 | 3987 |
3994 if (status) { | 3988 u->state->status = status; |
3995 u->state->status = status; | 3989 |
3996 timeout = u->conf->next_upstream_timeout; | 3990 timeout = u->conf->next_upstream_timeout; |
3997 | 3991 |
3998 if (u->peer.tries == 0 | 3992 if (u->peer.tries == 0 |
3999 || !(u->conf->next_upstream & ft_type) | 3993 || !(u->conf->next_upstream & ft_type) |
4000 || (u->request_sent && r->request_body_no_buffering) | 3994 || (u->request_sent && r->request_body_no_buffering) |
4001 || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) | 3995 || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) |
3996 { | |
3997 #if (NGX_HTTP_CACHE) | |
3998 | |
3999 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED | |
4000 && (u->conf->cache_use_stale & ft_type)) | |
4002 { | 4001 { |
4003 #if (NGX_HTTP_CACHE) | 4002 ngx_int_t rc; |
4004 | 4003 |
4005 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED | 4004 rc = u->reinit_request(r); |
4006 && (u->conf->cache_use_stale & ft_type)) | 4005 |
4007 { | 4006 if (rc == NGX_OK) { |
4008 ngx_int_t rc; | 4007 u->cache_status = NGX_HTTP_CACHE_STALE; |
4009 | 4008 rc = ngx_http_upstream_cache_send(r, u); |
4010 rc = u->reinit_request(r); | 4009 } |
4011 | 4010 |
4012 if (rc == NGX_OK) { | 4011 ngx_http_upstream_finalize_request(r, u, rc); |
4013 u->cache_status = NGX_HTTP_CACHE_STALE; | 4012 return; |
4014 rc = ngx_http_upstream_cache_send(r, u); | 4013 } |
4015 } | |
4016 | |
4017 ngx_http_upstream_finalize_request(r, u, rc); | |
4018 return; | |
4019 } | |
4020 #endif | 4014 #endif |
4021 | 4015 |
4022 ngx_http_upstream_finalize_request(r, u, status); | 4016 ngx_http_upstream_finalize_request(r, u, status); |
4023 return; | 4017 return; |
4024 } | |
4025 } | 4018 } |
4026 | 4019 |
4027 if (u->peer.connection) { | 4020 if (u->peer.connection) { |
4028 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 4021 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4029 "close http upstream connection: %d", | 4022 "close http upstream connection: %d", |