@@ -84,6 +84,7 @@ func (c *client) Start(ctx context.Context) (<-chan error, error) {
84
84
}
85
85
c .addrs .Store (addrs )
86
86
87
+ var aech <- chan error
87
88
if c .autoconn {
88
89
c .client = grpc .New (
89
90
append (
@@ -92,6 +93,13 @@ func (c *client) Start(ctx context.Context) (<-chan error, error) {
92
93
grpc .WithErrGroup (c .eg ),
93
94
)... ,
94
95
)
96
+ if c .client != nil {
97
+ aech , err = c .client .StartConnectionMonitor (ctx )
98
+ if err != nil {
99
+ close (ech )
100
+ return nil , err
101
+ }
102
+ }
95
103
}
96
104
97
105
err = c .discover (ctx , ech )
@@ -100,15 +108,6 @@ func (c *client) Start(ctx context.Context) (<-chan error, error) {
100
108
return nil , errors .Wrap (c .dscClient .Close (), err .Error ())
101
109
}
102
110
103
- var aech <- chan error
104
- if c .autoconn && c .client != nil {
105
- aech , err = c .client .StartConnectionMonitor (ctx )
106
- if err != nil {
107
- close (ech )
108
- return nil , err
109
- }
110
- }
111
-
112
111
c .eg .Go (safety .RecoverFunc (func () (err error ) {
113
112
defer close (ech )
114
113
fch := make (chan struct {}, 1 )
@@ -235,10 +234,10 @@ func (c *client) discover(ctx context.Context, ech chan<- error) (err error) {
235
234
Node : c .nodeName ,
236
235
}, copts ... )
237
236
if err != nil {
237
+ log .Warn ("failed to call discoverer.Node API" )
238
238
return nil , errors .ErrRPCCallFailed (c .dscAddr , err )
239
239
}
240
240
var wg sync.WaitGroup
241
- cond := sync .NewCond (new (sync.Mutex ))
242
241
cctx , cancel := context .WithCancel (ctx )
243
242
pch := make (chan string , len (nodes .GetNodes ()))
244
243
for _ , n := range nodes .GetNodes () {
@@ -251,19 +250,20 @@ func (c *client) discover(ctx context.Context, ech chan<- error) (err error) {
251
250
wg .Add (1 )
252
251
c .eg .Go (safety .RecoverFunc (func () (err error ) {
253
252
defer wg .Done ()
254
- cond .L .Lock ()
255
- cond .Wait ()
256
- cond .L .Unlock ()
253
+ log .Debug ("processing node name = %s" , node .GetName ())
257
254
for _ , pod := range node .GetPods ().GetPods () {
258
255
select {
259
256
case <- cctx .Done ():
257
+ log .Debug ("exit pods loop by context" )
260
258
return nil
261
259
default :
260
+ log .Debug ("%#v" , pod )
262
261
if pod != nil && pod .GetIp () != "" {
262
+ log .Debug ("processing pod name = %s" , pod .GetName ())
263
263
addr := fmt .Sprintf ("%s:%d" , pod .GetIp (), c .port )
264
264
if err = c .connect (ctx , addr ); err != nil {
265
265
err = errors .ErrAddrCouldNotDiscover (err , addr )
266
- log .Debug (err )
266
+ log .Warn (err )
267
267
ech <- err
268
268
err = nil
269
269
} else {
@@ -275,6 +275,7 @@ func (c *client) discover(ctx context.Context, ech chan<- error) (err error) {
275
275
}
276
276
}
277
277
}
278
+ log .Debug ("finished node = " + node .GetName ())
278
279
return nil
279
280
}))
280
281
}
@@ -285,23 +286,24 @@ func (c *client) discover(ctx context.Context, ech chan<- error) (err error) {
285
286
cancel ()
286
287
return nil
287
288
}))
288
- cond .Broadcast ()
289
289
for {
290
290
select {
291
291
case <- cctx .Done ():
292
292
if len (connected ) == 0 {
293
+ log .Warn ("connected addr is zero" )
293
294
return nil , errors .ErrAddrCouldNotDiscover (err , c .dns )
294
295
}
295
296
if c .onDiscover != nil {
296
297
return nil , c .onDiscover (ctx , c , connected )
297
298
}
298
299
return nil , nil
299
300
case addr := <- pch :
301
+ log .Debug ("connected addr = " + addr )
300
302
connected = append (connected , addr )
301
303
}
302
304
}
303
305
}); err != nil {
304
- log .Warn ("failed to discover addrs from discoverer API, trying to discover from dns..." )
306
+ log .Warn ("failed to discover addrs from discoverer API, trying to discover from dns..., %v" , err )
305
307
connected , err = c .dnsDiscovery (ctx , ech )
306
308
if err != nil {
307
309
return err
0 commit comments