From 8519421c87616366275a9716120baf83707a3ce9 Mon Sep 17 00:00:00 2001 From: satotake Date: Mon, 18 Jul 2022 11:41:46 +0900 Subject: [PATCH] fix leaked event after Close --- watcher/filenotify/fsevents_darwin.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/watcher/filenotify/fsevents_darwin.go b/watcher/filenotify/fsevents_darwin.go index 93db5f6886f..293a837f195 100644 --- a/watcher/filenotify/fsevents_darwin.go +++ b/watcher/filenotify/fsevents_darwin.go @@ -40,7 +40,6 @@ type eventStream struct { watcher *fsEventsWatcher basePath string removed chan bool - closed bool } type fsEventsWatcher struct { @@ -53,6 +52,9 @@ type fsEventsWatcher struct { } func (w *fsEventsWatcher) Events() <-chan fsnotify.Event { + if w.closed { + return nil + } return w.events } @@ -133,7 +135,6 @@ func (w *fsEventsWatcher) add(path string) error { w, path, make(chan bool), - false, } w.streams[path] = stream go func(stream *eventStream) { @@ -209,9 +210,7 @@ func (s *eventStream) convertEvent(e fsevents.Event) (fsnotify.Event, error) { } func (s *eventStream) sendEvent(e fsevents.Event) error { - if s.closed { - return nil - } + w := s.watcher ne, err := s.convertEvent(e) if err != nil { @@ -221,9 +220,9 @@ func (s *eventStream) sendEvent(e fsevents.Event) error { return nil } select { - case w.events <- ne: case <-w.done: return fmt.Errorf("closed") + case w.events <- ne: } return nil } @@ -231,8 +230,6 @@ func (s *eventStream) sendEvent(e fsevents.Event) error { func (w *fsEventsWatcher) sendErr(e error) error { select { case w.errors <- e: - // case <-w.done: - // return fmt.Errorf("closed") } return nil } @@ -287,7 +284,6 @@ func (w *fsEventsWatcher) remove(name string) error { if !exists { return errFSEventsWatcherStreamNotRegistered } - stream.closed = true close(stream.removed) delete(w.streams, name) return nil