Skip to content

Commit

Permalink
add file poller panic fix from 1.10.2
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Feb 24, 2016
1 parent 91fdfdd commit f9524a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
47 changes: 47 additions & 0 deletions daemon/logger/jsonfilelog/jsonfilelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,50 @@ func TestJSONFileLoggerWithLabelsEnv(t *testing.T) {
t.Fatalf("Wrong log attrs: %q, expected %q", extra, expected)
}
}

func BenchmarkJSONFileLoggerWithReader(b *testing.B) {
b.StopTimer()
b.ResetTimer()
cid := "a7317399f3f857173c6179d44823594f8294678dea9999662e5c625b5a1c7657"
dir, err := ioutil.TempDir("", "json-logger-bench")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(dir)

l, err := New(logger.Context{
ContainerID: cid,
LogPath: filepath.Join(dir, "container.log"),
})
if err != nil {
b.Fatal(err)
}
defer l.Close()
msg := &logger.Message{ContainerID: cid, Line: []byte("line"), Source: "src1"}
jsonlog, err := (&jsonlog.JSONLog{Log: string(msg.Line) + "\n", Stream: msg.Source, Created: msg.Timestamp}).MarshalJSON()
if err != nil {
b.Fatal(err)
}
b.SetBytes(int64(len(jsonlog)+1) * 30)

b.StartTimer()

go func() {
for i := 0; i < b.N; i++ {
for j := 0; j < 30; j++ {
l.Log(msg)
}
}
l.Close()
}()

lw := l.(logger.LogReader).ReadLogs(logger.ReadConfig{Follow: true})
watchClose := lw.WatchClose()
for {
select {
case <-lw.Msg:
case <-watchClose:
return
}
}
}
3 changes: 1 addition & 2 deletions pkg/filenotify/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ func (w *filePoller) Close() error {
w.remove(name)
delete(w.watches, name)
}
close(w.events)
close(w.errors)
return nil
}

Expand All @@ -146,6 +144,7 @@ func (w *filePoller) sendErr(e error, chClose <-chan struct{}) error {
// watch is responsible for polling the specified file for changes
// upon finding changes to a file or errors, sendEvent/sendErr is called
func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}) {
defer f.Close()
for {
time.Sleep(watchWaitTime)
select {
Expand Down
18 changes: 0 additions & 18 deletions pkg/filenotify/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,6 @@ func TestPollerClose(t *testing.T) {
t.Fatal(err)
}

select {
case _, open := <-w.Events():
if open {
t.Fatal("event chan should be closed")
}
default:
t.Fatal("event chan should be closed")
}

select {
case _, open := <-w.Errors():
if open {
t.Fatal("errors chan should be closed")
}
default:
t.Fatal("errors chan should be closed")
}

f, err := ioutil.TempFile("", "asdf")
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit f9524a4

Please sign in to comment.