Skip to content

Commit 32f7bb1

Browse files
Merge pull request #19727 from vrothberg/fix-19715
kube: notifyproxy: close once
2 parents 6009d16 + a5f6a4a commit 32f7bb1

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

pkg/domain/infra/abi/play.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
802802
initContainers = append(initContainers, ctr)
803803
}
804804

805-
var sdNotifyProxies []*notifyproxy.NotifyProxy // containers' sd-notify proxies
805+
// Callers are expected to close the proxies
806+
var sdNotifyProxies []*notifyproxy.NotifyProxy
806807

807808
for _, container := range podYAML.Spec.Containers {
808809
// Error out if the same name is used for more than one container
@@ -915,11 +916,6 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
915916
errors := make([]error, len(sdNotifyProxies))
916917
for i := range sdNotifyProxies {
917918
wg.Add(1)
918-
defer func() {
919-
if err := sdNotifyProxies[i].Close(); err != nil {
920-
logrus.Errorf("Closing sdnotify proxy %q: %v", sdNotifyProxies[i].SocketPath(), err)
921-
}
922-
}()
923919
go func(i int) {
924920
err := sdNotifyProxies[i].Wait()
925921
if err != nil {

pkg/systemd/notifyproxy/notifyproxy.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,16 @@ func New(tmpDir string) (*NotifyProxy, error) {
103103
// Start waiting for the READY message in the background. This way,
104104
// the proxy can be created prior to starting the container and
105105
// circumvents a race condition on writing/reading on the socket.
106-
proxy.waitForReady()
106+
proxy.listen()
107107

108108
return proxy, nil
109109
}
110110

111-
// waitForReady waits for the READY message in the background. The goroutine
112-
// returns on receiving READY or when the socket is closed.
113-
func (p *NotifyProxy) waitForReady() {
111+
// listen waits for the READY message in the background, and process file
112+
// descriptors and barriers send over the NOTIFY_SOCKET. The goroutine returns
113+
// when the socket is closed.
114+
func (p *NotifyProxy) listen() {
114115
go func() {
115-
// Read until the `READY` message is received or the connection
116-
// is closed.
117-
118116
// See https://github.com/containers/podman/issues/16515 for a description of the protocol.
119117
fdSize := unix.CmsgSpace(4)
120118
buffer := make([]byte, _notifyBufferMax)
@@ -128,6 +126,7 @@ func (p *NotifyProxy) waitForReady() {
128126
return
129127
}
130128
logrus.Errorf("Error reading unix message on socket %q: %v", p.socketPath, err)
129+
continue
131130
}
132131

133132
if n > _notifyBufferMax || oobn > _notifyFdMax*fdSize {
@@ -207,7 +206,7 @@ type Container interface {
207206
ID() string
208207
}
209208

210-
// WaitAndClose waits until receiving the `READY` notify message. Note that the
209+
// Wait waits until receiving the `READY` notify message. Note that the
211210
// this function must only be executed inside a systemd service which will kill
212211
// the process after a given timeout. If the (optional) container stopped
213212
// running before the `READY` is received, the waiting gets canceled and

test/system/260-sdnotify.bats

+2
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ none | false | false | 0
489489
podman_exit=0
490490
fi
491491
run_podman $podman_exit kube play --service-exit-code-propagation="$exit_code_prop" --service-container $fname
492+
# Make sure that there are no error logs (e.g., #19715)
493+
assert "$output" !~ "error msg="
492494
run_podman container inspect --format '{{.KubeExitCodePropagation}}' $service_container
493495
is "$output" "$exit_code_prop" "service container has the expected policy set in its annotations"
494496
run_podman wait $service_container

0 commit comments

Comments
 (0)