Skip to content

Commit

Permalink
Merge pull request #7629 from LK4D4/fix_follow_hang_on_stop
Browse files Browse the repository at this point in the history
Fix logs -f hanging on stopped containers
  • Loading branch information
crosbymichael committed Aug 25, 2014
2 parents 7556a42 + f04ef96 commit 228eda4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
}
}
}
if follow {
if follow && container.State.IsRunning() {
errors := make(chan error, 2)
if stdout {
stdoutPipe := container.StdoutLogPipe()
Expand Down
32 changes: 32 additions & 0 deletions integration-cli/docker_cli_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,35 @@ func TestLogsTail(t *testing.T) {
deleteContainer(cleanedContainerID)
logDone("logs - logs tail")
}

func TestLogsFollowStopped(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")

out, _, _, err := runCommandWithStdoutStderr(runCmd)
errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err))

cleanedContainerID := stripTrailingCharacters(out)
exec.Command(dockerBinary, "wait", cleanedContainerID).Run()

logsCmd := exec.Command(dockerBinary, "logs", "-f", cleanedContainerID)
if err := logsCmd.Start(); err != nil {
t.Fatal(err)
}

c := make(chan struct{})
go func() {
if err := logsCmd.Wait(); err != nil {
t.Fatal(err)
}
close(c)
}()

select {
case <-c:
case <-time.After(1 * time.Second):
t.Fatal("Following logs is hanged")
}

deleteContainer(cleanedContainerID)
logDone("logs - logs follow stopped container")
}

0 comments on commit 228eda4

Please sign in to comment.