From 78625f85a70dce5033a5cf13a9658cbd92444dd2 Mon Sep 17 00:00:00 2001 From: pasquier-s Date: Thu, 21 Dec 2017 11:07:43 +0100 Subject: [PATCH] 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. --- discovery/file/file.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discovery/file/file.go b/discovery/file/file.go index 3dedd90b8..777201302 100644 --- a/discovery/file/file.go +++ b/discovery/file/file.go @@ -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)