Merge pull request #37062 from cpuguy83/fix_logs_daemon_race
Fix race conditions in logs API
This commit is contained in:
commit
07dc3aa685
1 changed files with 12 additions and 3 deletions
|
@ -22,7 +22,7 @@ import (
|
|||
//
|
||||
// if it returns nil, the config channel will be active and return log
|
||||
// messages until it runs out or the context is canceled.
|
||||
func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *types.ContainerLogsOptions) (<-chan *backend.LogMessage, bool, error) {
|
||||
func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *types.ContainerLogsOptions) (messages <-chan *backend.LogMessage, isTTY bool, retErr error) {
|
||||
lg := logrus.WithFields(logrus.Fields{
|
||||
"module": "daemon",
|
||||
"method": "(*Daemon).ContainerLogs",
|
||||
|
@ -51,8 +51,10 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
|||
}
|
||||
if cLogCreated {
|
||||
defer func() {
|
||||
if err = cLog.Close(); err != nil {
|
||||
logrus.Errorf("Error closing logger: %v", err)
|
||||
if retErr != nil {
|
||||
if err = cLog.Close(); err != nil {
|
||||
logrus.Errorf("Error closing logger: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -101,6 +103,13 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
|||
// this goroutine functions as a shim between the logger and the caller.
|
||||
messageChan := make(chan *backend.LogMessage, 1)
|
||||
go func() {
|
||||
if cLogCreated {
|
||||
defer func() {
|
||||
if err = cLog.Close(); err != nil {
|
||||
logrus.Errorf("Error closing logger: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
// set up some defers
|
||||
defer logs.Close()
|
||||
|
||||
|
|
Loading…
Reference in a new issue