[PATCH] Upstream: max_fails doesn't respect the next_upstream config
    solomon 
    logchen2009 at gmail.com
       
    Thu Oct 30 06:48:54 UTC 2025
    
    
  
# HG changeset patch
# User Zhefeng Chen <logchen2009 at gmail.com>
# Date 1761731339 -28800
#      Wed Oct 29 17:48:59 2025 +0800
# Node ID b81b918263d445c32cb2cff5e2724e3cac62dab3
# Parent  c3be8460587196f376bccf29817c3a6523e18150
Upstream: max_fails doesn't respect the next_upstream config
In the description of `max_fails`, it says:
What is considered an unsuccessful attempt is defined by the
`proxy_next_upstream`, `fastcgi_next_upstreami`,
`uwsgi_next_upstream`, `scgi_next_upstream`,
`memcached_next_upstream`, and `grpc_next_upstream` directives.
But actually 403 and 404 are always considered an successful
attempt, while other cases are always considered an
unsuccessful attempt.
The `ngx_http_upstream_free_round_robin_peer` function depends
on this to update the health check state.
diff -r c3be84605871 -r b81b918263d4 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c      Tue Jul 15 22:22:53 2025 +0400
+++ b/src/http/ngx_http_upstream.c      Wed Oct 29 17:48:59 2025 +0800
@@ -4553,13 +4553,12 @@
             u->state->bytes_sent = u->peer.connection->sent;
         }
-        if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403
-            || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404)
+        if ((u->conf->next_upstream & ft_type) == ft_type)
         {
-            state = NGX_PEER_NEXT;
+            state = NGX_PEER_FAILED;
         } else {
-            state = NGX_PEER_FAILED;
+            state = NGX_PEER_NEXT;
         }
         u->peer.free(&u->peer, u->peer.data, state);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://freenginx.org/pipermail/nginx-devel/attachments/20251030/7c0e70f8/attachment.htm>
    
    
More information about the nginx-devel
mailing list