@@ -20,6 +20,7 @@ package grpc
2020
2121import (
2222 "context"
23+ "fmt"
2324 "strings"
2425 "sync"
2526
@@ -62,11 +63,15 @@ func newCCResolverWrapper(cc *ClientConn) *ccResolverWrapper {
6263 }
6364}
6465
65- // start builds the name resolver using the resolver.Builder in cc and returns
66- // any error encountered. It must always be the first operation performed on
67- // any newly created ccResolverWrapper, except that close may be called instead.
68- func (ccr * ccResolverWrapper ) start () error {
69- errCh := make (chan error )
66+ // start builds the name resolver using the resolver.Builder in cc.
67+ // If an error is encountered, it will report the error to the load balancing
68+ // policy via cc.ReportError(). This action allows the policy to set the channel
69+ // state to TransientFailure and ensures the error is propagated to new RPCs,
70+ // causing them to fail.
71+ // It must always be the first operation performed on any newly created
72+ // ccResolverWrapper, except that close may be called instead.
73+ func (ccr * ccResolverWrapper ) start () {
74+ doneCh := make (chan struct {})
7075 ccr .serializer .TrySchedule (func (ctx context.Context ) {
7176 if ctx .Err () != nil {
7277 return
@@ -90,11 +95,24 @@ func (ccr *ccResolverWrapper) start() error {
9095 } else {
9196 ccr .resolver , err = delegatingresolver .New (ccr .cc .parsedTarget , ccr , opts , ccr .cc .resolverBuilder , ccr .cc .dopts .enableLocalDNSResolution )
9297 }
93- errCh <- err
98+
99+ if err != nil {
100+ ccr .resolver = & nopResolver {}
101+ ccr .ReportError (fmt .Errorf ("resolver creation failed: %v" , err ))
102+ }
103+
104+ doneCh <- struct {}{}
94105 })
95- return <- errCh
106+ <- doneCh
96107}
97108
109+ type nopResolver struct {
110+ }
111+
112+ func (* nopResolver ) ResolveNow (resolver.ResolveNowOptions ) {}
113+
114+ func (* nopResolver ) Close () {}
115+
98116func (ccr * ccResolverWrapper ) resolveNow (o resolver.ResolveNowOptions ) {
99117 ccr .serializer .TrySchedule (func (ctx context.Context ) {
100118 if ctx .Err () != nil || ccr .resolver == nil {
0 commit comments