fix(transport): transport/grpc/resolver update instance's addrs not directly return with firstUpdateState

pull/2243/head
linxiaowei 2 years ago
parent 86eba94646
commit b7f09b3a37
  1. 1
      transport/grpc/resolver/discovery/builder.go
  2. 9
      transport/grpc/resolver/discovery/resolver.go

@ -91,6 +91,7 @@ func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, opts res
cancel: cancel, cancel: cancel,
insecure: b.insecure, insecure: b.insecure,
debugLogDisabled: b.debugLogDisabled, debugLogDisabled: b.debugLogDisabled,
firstUpdateState: true,
} }
go r.watch() go r.watch()
return r, nil return r, nil

@ -23,6 +23,7 @@ type discoveryResolver struct {
insecure bool insecure bool
debugLogDisabled bool debugLogDisabled bool
firstUpdateState bool
} }
func (r *discoveryResolver) watch() { func (r *discoveryResolver) watch() {
@ -72,11 +73,17 @@ func (r *discoveryResolver) update(ins []*registry.ServiceInstance) {
} }
if len(addrs) == 0 { if len(addrs) == 0 {
log.Warnf("[resolver] Zero endpoint found,refused to write, instances: %v", ins) log.Warnf("[resolver] Zero endpoint found,refused to write, instances: %v", ins)
return // Not directly return with firstUpdateState
// because gRPC client will block until the resolver has provided addresses or the context expires.
if !r.firstUpdateState {
return
}
} }
err := r.cc.UpdateState(resolver.State{Addresses: addrs}) err := r.cc.UpdateState(resolver.State{Addresses: addrs})
if err != nil { if err != nil {
log.Errorf("[resolver] failed to update state: %s", err) log.Errorf("[resolver] failed to update state: %s", err)
} else {
r.firstUpdateState = false
} }
if !r.debugLogDisabled { if !r.debugLogDisabled {

Loading…
Cancel
Save