|
@@ -64,6 +64,18 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
|
|
Follow: follow,
|
|
|
}
|
|
|
logs := logReader.ReadLogs(readConfig)
|
|
|
+ // Close logWatcher on exit
|
|
|
+ defer func() {
|
|
|
+ logs.Close()
|
|
|
+ if cLog != container.LogDriver {
|
|
|
+ // Since the logger isn't cached in the container, which
|
|
|
+ // occurs if it is running, it must get explicitly closed
|
|
|
+ // here to avoid leaking it and any file handles it has.
|
|
|
+ if err := cLog.Close(); err != nil {
|
|
|
+ logrus.Errorf("Error closing logger: %v", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
wf := ioutils.NewWriteFlusher(config.OutStream)
|
|
|
defer wf.Close()
|
|
@@ -84,19 +96,11 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
|
|
logrus.Errorf("Error streaming logs: %v", err)
|
|
|
return nil
|
|
|
case <-ctx.Done():
|
|
|
- logs.Close()
|
|
|
+ logrus.Debugf("logs: end stream, ctx is done: %v", ctx.Err())
|
|
|
return nil
|
|
|
case msg, ok := <-logs.Msg:
|
|
|
if !ok {
|
|
|
logrus.Debug("logs: end stream")
|
|
|
- logs.Close()
|
|
|
- if cLog != container.LogDriver {
|
|
|
- // Since the logger isn't cached in the container, which occurs if it is running, it
|
|
|
- // must get explicitly closed here to avoid leaking it and any file handles it has.
|
|
|
- if err := cLog.Close(); err != nil {
|
|
|
- logrus.Errorf("Error closing logger: %v", err)
|
|
|
- }
|
|
|
- }
|
|
|
return nil
|
|
|
}
|
|
|
logLine := msg.Line
|