MCPcopy Create free account
hub / github.com/cortexproject/cortex / watchDNSLoop

Method watchDNSLoop

pkg/util/dns_watcher.go:49–83  ·  view source on GitHub ↗

watchDNSLoop watches for changes in DNS and sends notifications.

(servCtx context.Context)

Source from the content-addressed store, hash-verified

47
48// watchDNSLoop watches for changes in DNS and sends notifications.
49func (w *dnsWatcher) watchDNSLoop(servCtx context.Context) error {
50 go func() {
51 // Close the watcher, when this service is asked to stop.
52 // Closing the watcher makes watchDNSLoop exit, since it only iterates on watcher updates, and has no other
53 // way to stop. We cannot close the watcher in `stopping` method, because it is only called *after*
54 // watchDNSLoop exits.
55 <-servCtx.Done()
56 w.watcher.Close()
57 }()
58
59 for {
60 updates, err := w.watcher.Next()
61 if err != nil {
62 // watcher.Next returns error when Close is called, but we call Close when our context is done.
63 // we don't want to report error in that case.
64 if servCtx.Err() != nil {
65 return nil
66 }
67 return errors.Wrapf(err, "error from DNS watcher")
68 }
69
70 for _, update := range updates {
71 switch update.Op {
72 case grpcutil.Add:
73 w.notifications.AddressAdded(update.Addr)
74
75 case grpcutil.Delete:
76 w.notifications.AddressRemoved(update.Addr)
77
78 default:
79 return fmt.Errorf("unknown op: %v", update.Op)
80 }
81 }
82 }
83}

Callers

nothing calls this directly

Calls 6

DoneMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65
AddressAddedMethod · 0.65
AddressRemovedMethod · 0.65

Tested by

no test coverage detected