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) errors := make(chan error, 2)
if stdout { if stdout {
stdoutPipe := container.StdoutLogPipe() stdoutPipe := container.StdoutLogPipe()
defer stdoutPipe.Close()
go func() { go func() {
errors <- jsonlog.WriteLog(stdoutPipe, job.Stdout, format) errors <- jsonlog.WriteLog(stdoutPipe, job.Stdout, format)
}() }()
} }
if stderr { if stderr {
stderrPipe := container.StderrLogPipe() stderrPipe := container.StderrLogPipe()
defer stderrPipe.Close()
go func() { go func() {
errors <- jsonlog.WriteLog(stderrPipe, job.Stderr, format) 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 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) dec := json.NewDecoder(src)
for { for {
l := &JSONLog{} l := &JSONLog{}
@ -40,6 +40,8 @@ func WriteLog(src io.Reader, dst io.WriteCloser, format string) error {
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintf(dst, "%s", line) if _, err := io.WriteString(dst, line); err != nil {
return err
}
} }
} }