Skip to content

Commit 8f89e60

Browse files
committed
debug
1 parent da46dc9 commit 8f89e60

File tree

2 files changed

+52
-56
lines changed

2 files changed

+52
-56
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ require (
6464
go.uber.org/zap v1.13.0
6565
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
6666
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2
67+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
6768
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
6869
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
6970
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1

registry/cache/cache.go

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -313,86 +313,81 @@ func (c *cache) update(res *registry.Result) {
313313
// run starts the cache watcher loop
314314
// it creates a new watcher if there's a problem
315315
func (c *cache) run(service string) {
316-
c.Lock()
317-
c.running = true
318-
c.Unlock()
319-
320316
// reset watcher on exit
321317
defer func() {
322318
c.Lock()
323-
c.watched = make(map[string]bool)
324-
c.running = false
319+
if _, ok := c.watched[service]; ok {
320+
delete(c.watched, service)
321+
}
325322
c.Unlock()
326323
}()
327324

328-
go func() {
329-
var a, b int
325+
var a, b int
330326

331-
for {
332-
// exit early if already dead
327+
for {
328+
// exit early if already dead
329+
if c.quit() {
330+
return
331+
}
332+
333+
// jitter before starting
334+
j := rand.Int63n(100)
335+
time.Sleep(time.Duration(j) * time.Millisecond)
336+
337+
// create new watcher
338+
watchOption := func(wo *registry.WatchOptions) {
339+
wo.Service = service
340+
}
341+
w, err := c.Registry.Watch(watchOption)
342+
if err != nil {
333343
if c.quit() {
334344
return
335345
}
336346

337-
// jitter before starting
338-
j := rand.Int63n(100)
339-
time.Sleep(time.Duration(j) * time.Millisecond)
347+
d := backoff(a)
348+
c.setStatus(err)
340349

341-
// create new watcher
342-
watchOption := func(wo *registry.WatchOptions) {
343-
wo.Service = service
344-
}
345-
w, err := c.Registry.Watch(watchOption)
346-
if err != nil {
347-
if c.quit() {
348-
return
350+
if a > 3 {
351+
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
352+
logger.Debug("rcache: ", err, " backing off ", d)
349353
}
354+
a = 0
355+
}
350356

351-
d := backoff(a)
352-
c.setStatus(err)
357+
time.Sleep(d)
358+
a++
353359

354-
if a > 3 {
355-
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
356-
logger.Debug("rcache: ", err, " backing off ", d)
357-
}
358-
a = 0
359-
}
360+
continue
361+
}
360362

361-
time.Sleep(d)
362-
a++
363+
// reset a
364+
a = 0
363365

364-
continue
366+
// watch for events
367+
if err := c.watch(w); err != nil {
368+
if c.quit() {
369+
return
365370
}
366371

367-
// reset a
368-
a = 0
369-
370-
// watch for events
371-
if err := c.watch(w); err != nil {
372-
if c.quit() {
373-
return
374-
}
375-
376-
d := backoff(b)
377-
c.setStatus(err)
372+
d := backoff(b)
373+
c.setStatus(err)
378374

379-
if b > 3 {
380-
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
381-
logger.Debug("rcache: ", err, " backing off ", d)
382-
}
383-
b = 0
375+
if b > 3 {
376+
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
377+
logger.Debug("rcache: ", err, " backing off ", d)
384378
}
385-
386-
time.Sleep(d)
387-
b++
388-
389-
continue
379+
b = 0
390380
}
391381

392-
// reset b
393-
b = 0
382+
time.Sleep(d)
383+
b++
384+
385+
continue
394386
}
395-
}()
387+
388+
// reset b
389+
b = 0
390+
}
396391
}
397392

398393
// watch loops the next event and calls update

0 commit comments

Comments
 (0)