Merge pull request #36305 from cpuguy83/35370_fix_logs_eof

Fix log tail with empty logs
This commit is contained in:
Akihiro Suda 2018-02-14 16:41:22 +09:00 committed by GitHub
commit e698b6e098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View File

@ -192,8 +192,12 @@ func (w *LogFile) ReadLogs(config logger.ReadConfig, watcher *logger.LogWatcher)
for _, f := range files {
seekers = append(seekers, f)
}
seekers = append(seekers, currentChunk)
tailFile(multireader.MultiReadSeeker(seekers...), watcher, w.createDecoder, config)
if currentChunk.Size() > 0 {
seekers = append(seekers, currentChunk)
}
if len(seekers) > 0 {
tailFile(multireader.MultiReadSeeker(seekers...), watcher, w.createDecoder, config)
}
}
w.mu.RLock()

View File

@ -0,0 +1,33 @@
package container
import (
"context"
"io/ioutil"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/request"
"github.com/docker/docker/pkg/stdcopy"
"github.com/stretchr/testify/assert"
)
// Regression test for #35370
// Makes sure that when following we don't get an EOF error when there are no logs
func TestLogsFollowTailEmpty(t *testing.T) {
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()
id := container.Run(t, ctx, client, container.WithCmd("sleep", "100000"))
defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true})
logs, err := client.ContainerLogs(ctx, id, types.ContainerLogsOptions{ShowStdout: true, Tail: "2"})
if logs != nil {
defer logs.Close()
}
assert.NoError(t, err)
_, err = stdcopy.StdCopy(ioutil.Discard, ioutil.Discard, logs)
assert.NoError(t, err)
}