[nginx] Upstream hash: fall back to round-robin if hash key is empty.

Roman Arutyunyan arut at nginx.com
Mon May 27 16:56:41 UTC 2019


details:   https://hg.nginx.org/nginx/rev/d964b0aee8e7
branches:  
changeset: 7513:d964b0aee8e7
user:      Niklas Keller <me at kelunik.com>
date:      Thu May 23 16:49:22 2019 +0300
description:
Upstream hash: fall back to round-robin if hash key is empty.

diffstat:

 src/http/modules/ngx_http_upstream_hash_module.c |  4 ++--
 src/stream/ngx_stream_upstream_hash_module.c     |  4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 99ef05560b96 -r d964b0aee8e7 src/http/modules/ngx_http_upstream_hash_module.c
--- a/src/http/modules/ngx_http_upstream_hash_module.c	Mon May 27 19:47:50 2019 +0300
+++ b/src/http/modules/ngx_http_upstream_hash_module.c	Thu May 23 16:49:22 2019 +0300
@@ -178,7 +178,7 @@ ngx_http_upstream_get_hash_peer(ngx_peer
 
     ngx_http_upstream_rr_peers_rlock(hp->rrp.peers);
 
-    if (hp->tries > 20 || hp->rrp.peers->single) {
+    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
         ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
         return hp->get_rr_peer(pc, &hp->rrp);
     }
@@ -509,7 +509,7 @@ ngx_http_upstream_get_chash_peer(ngx_pee
 
     ngx_http_upstream_rr_peers_wlock(hp->rrp.peers);
 
-    if (hp->tries > 20 || hp->rrp.peers->single) {
+    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
         ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
         return hp->get_rr_peer(pc, &hp->rrp);
     }
diff -r 99ef05560b96 -r d964b0aee8e7 src/stream/ngx_stream_upstream_hash_module.c
--- a/src/stream/ngx_stream_upstream_hash_module.c	Mon May 27 19:47:50 2019 +0300
+++ b/src/stream/ngx_stream_upstream_hash_module.c	Thu May 23 16:49:22 2019 +0300
@@ -178,7 +178,7 @@ ngx_stream_upstream_get_hash_peer(ngx_pe
 
     ngx_stream_upstream_rr_peers_rlock(hp->rrp.peers);
 
-    if (hp->tries > 20 || hp->rrp.peers->single) {
+    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
         ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
         return hp->get_rr_peer(pc, &hp->rrp);
     }
@@ -511,7 +511,7 @@ ngx_stream_upstream_get_chash_peer(ngx_p
 
     ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers);
 
-    if (hp->tries > 20 || hp->rrp.peers->single) {
+    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
         ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
         return hp->get_rr_peer(pc, &hp->rrp);
     }


More information about the nginx-devel mailing list