mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 14:57:40 -08:00
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:
parent
2881d73ed8
commit
78625f85a7
|
@ -114,14 +114,13 @@ func (d *Discovery) watchFiles() {
|
||||||
|
|
||||||
// Run implements the TargetProvider interface.
|
// Run implements the TargetProvider interface.
|
||||||
func (d *Discovery) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
func (d *Discovery) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
defer d.stop()
|
|
||||||
|
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
level.Error(d.logger).Log("msg", "Error adding file watcher", "err", err)
|
level.Error(d.logger).Log("msg", "Error adding file watcher", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d.watcher = watcher
|
d.watcher = watcher
|
||||||
|
defer d.stop()
|
||||||
|
|
||||||
d.refresh(ctx, ch)
|
d.refresh(ctx, ch)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue