Skip to content

Commit

Permalink
Close logs pipes and catch write errors
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Morozov <[email protected]>
  • Loading branch information
LK4D4 committed Sep 22, 2014
1 parent fd3f2e1 commit a7ee201
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions daemon/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
errors := make(chan error, 2)
if stdout {
stdoutPipe := container.StdoutLogPipe()
defer stdoutPipe.Close()
go func() {
errors <- jsonlog.WriteLog(stdoutPipe, job.Stdout, format)
}()
}
if stderr {
stderrPipe := container.StderrLogPipe()
defer stderrPipe.Close()
go func() {
errors <- jsonlog.WriteLog(stderrPipe, job.Stderr, format)
}()
Expand Down
4 changes: 3 additions & 1 deletion pkg/jsonlog/jsonlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func WriteLog(src io.Reader, dst io.Writer, format string) error {
if err != nil {
return err
}
fmt.Fprintf(dst, "%s", line)
if _, err := io.WriteString(dst, line); err != nil {
return err
}
}
}

0 comments on commit a7ee201

Please sign in to comment.