From 5c84486ca37a351e7ebeb67907d5c43b2c5ddcd8 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 11 Oct 2012 21:47:58 -0700 Subject: [PATCH] check the stop channel while waiting on inotify fixes http://bugs.activestate.com/show_bug.cgi?id=95718#c3 --- tail.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tail.go b/tail.go index c698c15..172a056 100644 --- a/tail.go +++ b/tail.go @@ -146,30 +146,33 @@ func (tail *Tail) tailFileSync(end bool, retry bool) { changes = tail.watcher.ChangeEvents() } - //log.Println("WAITING ", tail.Filename) - _, ok := <-changes - //log.Println("RECEIVED ", tail.Filename) - - if !ok { - // file got deleted/renamed - if retry { - log.Printf("File %s has been moved (logrotation?); reopening..", tail.Filename) - tail.reopen(retry) - log.Printf("File %s has been reopened.", tail.Filename) - tail.reader = bufio.NewReaderSize(tail.file, tail.maxlinesize) - changes = nil - continue - } else { - log.Printf("File %s has gone away; skipping this file.\n", tail.Filename) - tail.close() - return + select { + case _, ok := <-changes: + if !ok { + // file got deleted/renamed + if retry { + log.Printf("File %s has been moved (logrotation?); reopening..", tail.Filename) + tail.reopen(retry) + log.Printf("File %s has been reopened.", tail.Filename) + tail.reader = bufio.NewReaderSize(tail.file, tail.maxlinesize) + changes = nil + continue + } else { + log.Printf("File %s has gone away; skipping this file.\n", tail.Filename) + tail.close() + return + } } + case <-tail.stop: + // stop the tailer if requested. + // FIXME: respect DRY (see below) + return } + } } // stop the tailer if requested. - // FIXME: won't happen promptly; http://bugs.activestate.com/show_bug.cgi?id=95718#c3 select { case <-tail.stop: return