Skip to content

Commit

Permalink
Issue 97 Fixing deferred RemoveWatch() due to which tailing stops (ge…
Browse files Browse the repository at this point in the history
…ts stuck) in certain conditions
  • Loading branch information
Arun Mathew committed Aug 1, 2016
1 parent 3ca1edc commit 48cd000
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion watch/inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange
fw.Size = pos

go func() {
defer RemoveWatch(fw.Filename)

events := Events(fw.Filename)

Expand All @@ -88,9 +87,11 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange
select {
case evt, ok = <-events:
if !ok {
RemoveWatch(fw.Filename)
return
}
case <-t.Dying():
RemoveWatch(fw.Filename)
return
}

Expand All @@ -99,13 +100,15 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange
fallthrough

case evt.Op&fsnotify.Rename == fsnotify.Rename:
RemoveWatch(fw.Filename)
changes.NotifyDeleted()
return

case evt.Op&fsnotify.Write == fsnotify.Write:
fi, err := os.Stat(fw.Filename)
if err != nil {
if os.IsNotExist(err) {
RemoveWatch(fw.Filename)
changes.NotifyDeleted()
return
}
Expand Down

0 comments on commit 48cd000

Please sign in to comment.