mirror of
https://github.com/containers/podman.git
synced 2025-07-13 17:31:21 +08:00
kube play: sdnotify proxy: use a wait group
Use a wait group to a) wait for all proxies in parallel b) avoid the potential for ABBA deadlocks [NO NEW TESTS NEEDED] as it is not changing functionality Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
buildahDefine "github.com/containers/buildah/define"
|
buildahDefine "github.com/containers/buildah/define"
|
||||||
"github.com/containers/common/libimage"
|
"github.com/containers/common/libimage"
|
||||||
@ -699,9 +700,24 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
|
|||||||
fmt.Println(playKubePod.ContainerErrors)
|
fmt.Println(playKubePod.ContainerErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for each proxy to receive a READY message.
|
// Wait for each proxy to receive a READY message. Use a wait
|
||||||
for _, proxy := range sdNotifyProxies {
|
// group to prevent the potential for ABBA kinds of deadlocks.
|
||||||
if err := proxy.WaitAndClose(); err != nil {
|
var wg sync.WaitGroup
|
||||||
|
errors := make([]error, len(sdNotifyProxies))
|
||||||
|
for i := range sdNotifyProxies {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int) {
|
||||||
|
err := sdNotifyProxies[i].WaitAndClose()
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("waiting for sd-notify proxy: %w", err)
|
||||||
|
}
|
||||||
|
errors[i] = err
|
||||||
|
wg.Done()
|
||||||
|
}(i)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for _, err := range errors {
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user