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. 7
      transport/grpc/resolver/discovery/resolver.go

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

@ -23,6 +23,7 @@ type discoveryResolver struct {
insecure bool
debugLogDisabled bool
firstUpdateState bool
}
func (r *discoveryResolver) watch() {
@ -72,11 +73,17 @@ func (r *discoveryResolver) update(ins []*registry.ServiceInstance) {
}
if len(addrs) == 0 {
log.Warnf("[resolver] Zero endpoint found,refused to write, instances: %v", ins)
// 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})
if err != nil {
log.Errorf("[resolver] failed to update state: %s", err)
} else {
r.firstUpdateState = false
}
if !r.debugLogDisabled {

Loading…
Cancel
Save