Skip to content

Commit

Permalink
fix Linux tailer shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Nov 21, 2017
1 parent 8dec7e4 commit cdc2cd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
10 changes: 10 additions & 0 deletions tailer/fileTailer.go
Expand Up @@ -143,6 +143,16 @@ func runFileTailer(path string, readall bool, failOnMissingFile bool, logger sim
}
return
case evnts := <-eventLoop.Events():
if evnts == nil {
select {
case <-done:
// The tailer is shutting down and closed the 'done' and 'errors' channels. This is ok.
default:
// 'done' is still open, the tailer is not shutting down. This is a bug.
writeError(errors, done, "failed to watch %v: unknown error", abspath)
}
return
}
var freshLines []string
file, freshLines, err = evnts.Process(file, reader, abspath, logger)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tailer/fileTailer_linux.go
Expand Up @@ -103,7 +103,7 @@ func (w *watcher) StartEventLoop() EventLoop {
event.Name = strings.TrimRight(string(bytes[0:event.Len]), "\000")
}
if event.Mask&syscall.IN_IGNORED == syscall.IN_IGNORED {
// eventLoop.Close() was called.
// eventLoop.Close() was called or log dir was deleted
return
}
eventsWithName = append(eventsWithName, event)
Expand Down
20 changes: 14 additions & 6 deletions tailer/fileTailer_test.go
Expand Up @@ -608,12 +608,20 @@ func runTestShutdown(t *testing.T, mode string) {
default:
t.Fatalf("Unknown mode: %v", mode)
}
_, ok := <-eventLoop.Errors()
if ok {
t.Fatalf("error channel not closed")
select {
case _, ok := <-eventLoop.Errors():
if ok {
t.Fatalf("error channel not closed")
}
case <-time.After(5 * time.Second):
t.Fatalf("timeout while waiting for errors channel to be closed.")
}
_, ok = <-eventLoop.Events()
if ok {
t.Fatalf("events channel not closed")
select {
case _, ok := <-eventLoop.Events():
if ok {
t.Fatalf("events channel not closed")
}
case <-time.After(5 * time.Second):
t.Fatalf("timeout while waiting for errors channel to be closed.")
}
}

0 comments on commit cdc2cd7

Please sign in to comment.