From dc5c4295348dfbdcaba5a3a4e97749cec543ca28 Mon Sep 17 00:00:00 2001 From: holmes1412 Date: Thu, 27 May 2021 23:36:49 +0800 Subject: [PATCH] avoid Upstream check_and_get() with addr==NULL in consistent hash policy --- src/nameservice/UpstreamPolicies.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nameservice/UpstreamPolicies.cc b/src/nameservice/UpstreamPolicies.cc index 69257775..541cfc49 100644 --- a/src/nameservice/UpstreamPolicies.cc +++ b/src/nameservice/UpstreamPolicies.cc @@ -206,15 +206,16 @@ bool UPSGroupPolicy::select(const ParsedURI& uri, WFNSTracing *tracing, } /* - * flag true : guarantee addr != NULL, and please return an available one. - * if no available addr, return NULL. - * false: addr may be NULL, means addr maybe useful but want one any way. + * flag true : return an available one. If not exists, return NULL. + * false: means addr maybe group-alive. + * If addr is not available, get one from addr->group. */ inline const EndpointAddress *UPSGroupPolicy::check_and_get(const EndpointAddress *addr, bool flag, WFNSTracing *tracing) { UPSAddrParams *params = static_cast(addr->params); + if (flag == true) // && addr->fail_count >= addr->params->max_fails { if (params->group_id == -1) @@ -440,6 +441,9 @@ const EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int h } } + if (!addr) + return NULL; + return this->check_and_get(addr, false, NULL); }