func processDyingEnv(client apiundertaker.UndertakerClient, clock uc.Clock, stopCh <-chan struct{}) error { // ProcessDyingEnviron will fail quite a few times before it succeeds as // it is being woken up as every machine or service changes. We ignore the // error here and rely on the logging inside the ProcessDyingEnviron. if err := client.ProcessDyingEnviron(); err == nil { return nil } watcher, err := client.WatchEnvironResources() if err != nil { return errors.Trace(err) } defer watcher.Stop() for { select { case _, ok := <-watcher.Changes(): if !ok { return watcher.Err() } err := client.ProcessDyingEnviron() if err != nil { // Yes, we ignore the error. See comment above. continue } return nil case <-stopCh: return tomb.ErrDying } } }