diff --git a/daemon/logger/jsonfilelog/jsonfilelog.go b/daemon/logger/jsonfilelog/jsonfilelog.go index 383aada82..4703f64b9 100644 --- a/daemon/logger/jsonfilelog/jsonfilelog.go +++ b/daemon/logger/jsonfilelog/jsonfilelog.go @@ -259,7 +259,8 @@ func (l *JSONFileLogger) readLogs(logWatcher *logger.LogWatcher, config logger.R if !config.Follow { return } - if config.Tail == 0 { + + if config.Tail >= 0 { latestFile.Seek(0, os.SEEK_END) } diff --git a/daemon/logger/logger.go b/daemon/logger/logger.go index 96421f4b9..39c1512de 100644 --- a/daemon/logger/logger.go +++ b/daemon/logger/logger.go @@ -2,6 +2,7 @@ package logger import ( "errors" + "sync" "time" "github.com/docker/docker/pkg/timeutils" @@ -51,6 +52,7 @@ type LogWatcher struct { // For sending error messages that occur while while reading logs Err chan error closeNotifier chan struct{} + closeOnce sync.Once } // NewLogWatcher returns a new LogWatcher. @@ -64,7 +66,12 @@ func NewLogWatcher() *LogWatcher { // Close notifies the underlying log reader to stop func (w *LogWatcher) Close() { - close(w.closeNotifier) + // only close if not already closed + select { + case <-w.closeNotifier: + default: + close(w.closeNotifier) + } } // WatchClose returns a channel receiver that receives notification when the watcher has been closed