From 16c346eba40dfb30001afb74d5abc0ea8bd42865 Mon Sep 17 00:00:00 2001 From: longXboy Date: Wed, 14 Aug 2019 10:26:05 +0800 Subject: [PATCH] fix resolver bug --- pkg/net/rpc/warden/CHANGELOG.md | 3 +++ pkg/net/rpc/warden/resolver/resolver.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/net/rpc/warden/CHANGELOG.md b/pkg/net/rpc/warden/CHANGELOG.md index 7bd96bbc7..10965198c 100644 --- a/pkg/net/rpc/warden/CHANGELOG.md +++ b/pkg/net/rpc/warden/CHANGELOG.md @@ -1,5 +1,8 @@ ### net/rpc/warden +##### Version 1.1.21 +1. fix resolver bug + ##### Version 1.1.20 1. client增加timeoutCallOpt强制覆盖每次请求的timeout diff --git a/pkg/net/rpc/warden/resolver/resolver.go b/pkg/net/rpc/warden/resolver/resolver.go index 06b0bf8e5..a8039a646 100644 --- a/pkg/net/rpc/warden/resolver/resolver.go +++ b/pkg/net/rpc/warden/resolver/resolver.go @@ -128,19 +128,24 @@ func (r *Resolver) updateproc() { return } } - if ins, ok := r.nr.Fetch(context.Background()); ok { - instances, ok := ins.Instances[r.zone] - if !ok { - for _, value := range ins.Instances { + if insMap, ok := r.nr.Fetch(context.Background()); ok { + instances, _ := insMap[r.zone] + res := r.filter(instances) + if len(res) == 0 { + for _, value := range insMap { instances = append(instances, value...) } + res = r.filter(instances) } - r.newAddress(r.filter(instances)) + r.newAddress(res) } } } func (r *Resolver) filter(backends []*naming.Instance) (instances []*naming.Instance) { + if len(backends) == 0 { + return + } for _, ins := range backends { //如果r.clusters的长度大于0说明需要进行集群选择 if _, ok := r.clusters[ins.Metadata[naming.MetaCluster]]; !ok && len(r.clusters) > 0 {