Fix race condition on file SD (#3468)

The file discovery should only stop the watcher if it has been created
otherwise it may trigger a segmentation fault.
This commit is contained in:
pasquier-s 2017-12-21 11:07:43 +01:00 committed by Brian Brazil
parent 2881d73ed8
commit 78625f85a7

View file

@ -114,14 +114,13 @@ func (d *Discovery) watchFiles() {
// Run implements the TargetProvider interface.
func (d *Discovery) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
defer d.stop()
watcher, err := fsnotify.NewWatcher()
if err != nil {
level.Error(d.logger).Log("msg", "Error adding file watcher", "err", err)
return
}
d.watcher = watcher
defer d.stop()
d.refresh(ctx, ch)