mirror of
https://github.com/docker/cli.git
synced 2026-01-16 20:22:36 +03:00
Merge pull request #8159 from LK4D4/fix_goroutine_leak_in_logs
Fix goroutine leak in logs following Upstream-commit: 9c7d97561499b1fd92bef755ea485b6942e65a66 Component: engine
This commit is contained in:
@@ -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)
|
||||
}()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user