Merge pull request #8159 from LK4D4/fix_goroutine_leak_in_logs

Fix goroutine leak in logs following
This commit is contained in:
Tibor Vass 2014-09-22 11:16:48 -04:00
commit 9c7d975614
2 changed files with 6 additions and 2 deletions

View file

@ -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)
}()

View file

@ -25,7 +25,7 @@ func (jl *JSONLog) Format(format string) (string, error) {
return fmt.Sprintf("[%s] %s", jl.Created.Format(format), jl.Log), nil
}
func WriteLog(src io.Reader, dst io.WriteCloser, format string) error {
func WriteLog(src io.Reader, dst io.Writer, format string) error {
dec := json.NewDecoder(src)
for {
l := &JSONLog{}
@ -40,6 +40,8 @@ func WriteLog(src io.Reader, dst io.WriteCloser, format string) error {
if err != nil {
return err
}
fmt.Fprintf(dst, "%s", line)
if _, err := io.WriteString(dst, line); err != nil {
return err
}
}
}