Gracefully handle situation when container details have not yet loaded

This should be very rare but it does happen sometimes
This commit is contained in:
Jesse Duffield 2024-05-26 12:27:01 +10:00
parent 623fdb4f33
commit 8a0fcf99f4

View file

@ -119,7 +119,24 @@ func (gui *Gui) writeContainerLogs(container *commands.Container, ctx context.Co
}
defer readCloser.Close()
if container.DetailsLoaded() && container.Details.Config.Tty {
if !container.DetailsLoaded() {
// loop until the details load or context is cancelled, using timer
ticker := time.NewTicker(time.Millisecond * 100)
defer ticker.Stop()
outer:
for {
select {
case <-ctx.Done():
return nil
case <-ticker.C:
if container.DetailsLoaded() {
break outer
}
}
}
}
if container.Details.Config.Tty {
_, err = io.Copy(writer, readCloser)
if err != nil {
return err