From c4ebe9e2ad77f34151ac59c8bf747790be2bd6d7 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 24 Oct 2022 17:32:40 +0200 Subject: [PATCH] notifyproxy: fix container watcher The notify proxy has a watcher to check whether the container has left the running state. In that case, Podman should stop waiting for the ready message to prevent a dead lock. Fix this watcher but adding a loop. Fixes the dead lock in #16076 surfacing in a timeout. The underlying issue persists though. Also use a timer in the select statement to prevent the goroutine from running unnecessarily long [NO NEW TESTS NEEDED] Signed-off-by: Valentin Rothberg --- pkg/systemd/notifyproxy/notifyproxy.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/systemd/notifyproxy/notifyproxy.go b/pkg/systemd/notifyproxy/notifyproxy.go index e9dd48c51b71..b5010cbc85e5 100644 --- a/pkg/systemd/notifyproxy/notifyproxy.go +++ b/pkg/systemd/notifyproxy/notifyproxy.go @@ -183,20 +183,21 @@ func (p *NotifyProxy) WaitAndClose() error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() go func() { - select { - case <-ctx.Done(): - return - default: - state, err := p.container.State() - if err != nil { - p.errorChan <- err - return - } - if state != define.ContainerStateRunning { - p.errorChan <- fmt.Errorf("%w: %s", ErrNoReadyMessage, p.container.ID()) + for { + select { + case <-ctx.Done(): return + case <-time.After(time.Second): + state, err := p.container.State() + if err != nil { + p.errorChan <- err + return + } + if state != define.ContainerStateRunning { + p.errorChan <- fmt.Errorf("%w: %s", ErrNoReadyMessage, p.container.ID()) + return + } } - time.Sleep(time.Second) } }() }