watchDNSLoop watches for changes in DNS and sends notifications.
(servCtx context.Context)
| 47 | |
| 48 | // watchDNSLoop watches for changes in DNS and sends notifications. |
| 49 | func (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 | } |
nothing calls this directly
no test coverage detected