Skip to content

Commit

Permalink
Merge pull request #23271 from giuseppe/drop-unmount-for-overlay-storage
Browse files Browse the repository at this point in the history
test: podman system service doesn't leak mount on termination
  • Loading branch information
openshift-merge-bot[bot] authored Jul 15, 2024
2 parents 2f673aa + b08b630 commit 88c68a4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
5 changes: 4 additions & 1 deletion cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/libpod/shutdown"
"github.com/containers/podman/v5/pkg/bindings"
"github.com/containers/podman/v5/pkg/checkpoint/crutils"
"github.com/containers/podman/v5/pkg/domain/entities"
Expand Down Expand Up @@ -124,9 +125,11 @@ func Execute() {
fmt.Fprintln(os.Stderr, formatError(err))
}

_ = shutdown.Stop()

if requireCleanup {
// The cobra post-run is not being executed in case of
// a previous error , so make sure that the engine(s)
// a previous error, so make sure that the engine(s)
// are correctly shutdown.
//
// See https://github.com/spf13/cobra/issues/914
Expand Down
11 changes: 7 additions & 4 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
}
}

if err := makeRuntime(ctx, runtime); err != nil {
return nil, err
}

if err := shutdown.Register("libpod", func(sig os.Signal) error {
if runtime.store != nil {
_, _ = runtime.store.Shutdown(false)
}
// For `systemctl stop podman.service` support, exit code should be 0
if sig == syscall.SIGTERM {
os.Exit(0)
Expand All @@ -225,10 +232,6 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
return nil, fmt.Errorf("starting shutdown signal handler: %w", err)
}

if err := makeRuntime(ctx, runtime); err != nil {
return nil, err
}

runtime.config.CheckCgroupsAndAdjustConfig()

return runtime, nil
Expand Down
5 changes: 5 additions & 0 deletions libpod/shutdown/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func Stop() error {
return nil
}

// if the signal handler is running, wait that it terminates
handlerLock.Lock()
defer handlerLock.Unlock()
// it doesn't need to be in the critical section, but staticcheck complains if
// the critical section is empty.
cancelChan <- true

return nil
Expand Down
11 changes: 0 additions & 11 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

var (
Expand Down Expand Up @@ -1057,16 +1056,6 @@ func rmAll(podmanBin string, path string) {
GinkgoWriter.Printf("%v\n", err)
}
} else {
// When using overlay as root, podman leaves a stray mount behind.
// This leak causes remote tests to take a loooooong time, which
// then causes Cirrus to time out. Unmount that stray.
overlayPath := path + "/root/overlay"
if _, err := os.Stat(overlayPath); err == nil {
if err = unix.Unmount(overlayPath, unix.MNT_DETACH); err != nil {
GinkgoWriter.Printf("Error unmounting %s: %v\n", overlayPath, err)
}
}

if err = os.RemoveAll(path); err != nil {
GinkgoWriter.Printf("%q\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/libpod_suite_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (p *PodmanTestIntegration) StartRemoteService() {
}

func (p *PodmanTestIntegration) StopRemoteService() {
if err := p.RemoteSession.Kill(); err != nil {
if err := p.RemoteSession.Signal(syscall.SIGTERM); err != nil {
GinkgoWriter.Printf("unable to clean up service %d, %v\n", p.RemoteSession.Pid, err)
}
if _, err := p.RemoteSession.Wait(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/system/001-basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ run_podman --noout system connection ls
run_podman --log-level=debug run --rm $IMAGE true
is "$output" ".*Shutting down engines.*"
run_podman 125 --log-level=debug run dockah://rien.de/rien:latest
is "${lines[-1]}" ".*Shutting down engines"
is "$output" ".*Shutting down engines.*"
}

# vim: filetype=sh

0 comments on commit 88c68a4

Please sign in to comment.