Skip to content

Commit

Permalink
fix leaked event after Close
Browse files Browse the repository at this point in the history
  • Loading branch information
satotake committed Jul 18, 2022
1 parent 5951726 commit 8519421
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions watcher/filenotify/fsevents_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type eventStream struct {
watcher *fsEventsWatcher
basePath string
removed chan bool
closed bool
}

type fsEventsWatcher struct {
Expand All @@ -53,6 +52,9 @@ type fsEventsWatcher struct {
}

func (w *fsEventsWatcher) Events() <-chan fsnotify.Event {
if w.closed {
return nil
}
return w.events
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -221,18 +220,16 @@ 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
}

func (w *fsEventsWatcher) sendErr(e error) error {
select {
case w.errors <- e:
// case <-w.done:
// return fmt.Errorf("closed")
}
return nil
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8519421

Please sign in to comment.