mirror of
https://github.com/clearlinux/docker.git
synced 2026-08-21 21:25:48 +00:00
Ensure reader position is at the end after tailing
After tailing a file, if the number of lines requested is > the number
of lines in the file, this would cause a json unmarshalling error to
occur when we later try to go follow the file.
So brute force set it to the end if any tailing occurred.
There is potential that there could be some missing log messages if logs
are being written very quickly, however I was not able to make this
happen even with `while true; do echo hello; done`, so this is probably
acceptable.
While testing this I also found a panic in LogWatcher.Close can be
called twice due to a race. Fix channel close to only close when there
has been no signal to the channel.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit c57faa91e2)
This commit is contained in:
committed by
David Calavera
parent
2f7145b1c5
commit
0f5e2fd479
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user