Skip to content

Commit bae05c9

Browse files
authored
Merge pull request #4857 from haytok/fix-to-wait-for-logger-on-stopped-containers
fix: wait for logger to finish before reading logs of stopped containers
2 parents 3f40c11 + 1872f69 commit bae05c9

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

pkg/cmd/container/logs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ func Logs(ctx context.Context, client *containerd.Client, container string, opti
105105
}
106106
}
107107

108+
// When follow was requested but the task has already stopped,
109+
// wait for the logger to finish writing before reading the log file.
110+
if !follow && options.Follow {
111+
if err := logging.WaitForLogger(dataStore, l[labels.Namespace], found.Container.ID()); err != nil {
112+
log.G(ctx).WithError(err).Warn("failed to wait for logger shutdown")
113+
}
114+
}
115+
108116
var detailPrefix string
109117
if options.Details {
110118
if logConfigJSON, ok := l["nerdctl/log-config"]; ok {

0 commit comments

Comments
 (0)