Merge pull request #23835 from swernli/loggerfix
Fixing file handle leak for "docker logs" Upstream-commit: 7eae48cd21f12a64c97c76f60412f32a2f1ade78 Component: engine
This commit is contained in:
@ -77,6 +77,9 @@ func (l *JSONFileLogger) readLogs(logWatcher *logger.LogWatcher, config logger.R
|
||||
}
|
||||
|
||||
if !config.Follow {
|
||||
if err := latestFile.Close(); err != nil {
|
||||
logrus.Errorf("Error closing file: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -87,6 +87,13 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user