lock the mutex before working with the `fileEventWatchers` (#5043)

Signed-off-by: Edward Welch <edward.welch@grafana.com>
pull/5049/head
Ed Welch 4 years ago committed by GitHub
parent 564f833a30
commit ba91a0e48a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      clients/pkg/promtail/targets/file/filetargetmanager.go

@ -326,6 +326,11 @@ func (s *targetSyncer) sync(groups []*targetgroup.Group, targetEventHandler chan
// sendFileCreateEvent sends file creation events to only the targets with matched path.
func (s *targetSyncer) sendFileCreateEvent(event fsnotify.Event) {
// Lock the mutex because other threads are manipulating s.fileEventWatchers which can lead to a deadlock
// where we send events to channels where nobody is listening anymore
s.mtx.Lock()
defer s.mtx.Unlock()
for path, watcher := range s.fileEventWatchers {
matched, err := doublestar.Match(path, event.Name)
if err != nil {

Loading…
Cancel
Save