From 0898b338b0eb25b10e0b565324887690bdb5cc30 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Fri, 1 Mar 2024 10:43:43 -0600 Subject: [PATCH] Use stop timeout of zero for system reset when performing a system reset with containers that run somewhere where a soft kill wont work (like sleep), containers will wait 10 seconds before terminating with a sigkill. But for a forceful action like system reset, we should outright set no timeout so containers stop quickly and are not waiting on a timeout Fixes #21874 Signed-off-by: Brent Baude --- libpod/reset.go | 8 ++++---- test/e2e/system_reset_test.go | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libpod/reset.go b/libpod/reset.go index 187bcbf4ba..955fcdff2d 100644 --- a/libpod/reset.go +++ b/libpod/reset.go @@ -108,13 +108,13 @@ func (r *Runtime) Reset(ctx context.Context) error { return define.ErrRuntimeStopped } - var timeout *uint + var timeout uint = 0 pods, err := r.GetAllPods() if err != nil { return err } for _, p := range pods { - if ctrs, err := r.RemovePod(ctx, p, true, true, timeout); err != nil { + if ctrs, err := r.RemovePod(ctx, p, true, true, &timeout); err != nil { if errors.Is(err, define.ErrNoSuchPod) { continue } @@ -133,7 +133,7 @@ func (r *Runtime) Reset(ctx context.Context) error { } for _, c := range ctrs { - if ctrs, _, err := r.RemoveContainerAndDependencies(ctx, c, true, true, timeout); err != nil { + if ctrs, _, err := r.RemoveContainerAndDependencies(ctx, c, true, true, &timeout); err != nil { for ctr, err := range ctrs { logrus.Errorf("Error removing container %s: %v", ctr, err) } @@ -163,7 +163,7 @@ func (r *Runtime) Reset(ctx context.Context) error { return err } for _, v := range volumes { - if err := r.RemoveVolume(ctx, v, true, timeout); err != nil { + if err := r.RemoveVolume(ctx, v, true, &timeout); err != nil { if errors.Is(err, define.ErrNoSuchVolume) { continue } diff --git a/test/e2e/system_reset_test.go b/test/e2e/system_reset_test.go index f71b29819e..0e641e99e2 100644 --- a/test/e2e/system_reset_test.go +++ b/test/e2e/system_reset_test.go @@ -92,12 +92,16 @@ var _ = Describe("podman system reset", Serial, func() { ctrName := "testctr" port1 := GetPort() port2 := GetPort() - session := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "top"}) + session := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "sleep", "inf"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) + // run system reset on a container that is running + // set a timeout of 9 seconds, which tests that reset is using the timeout + // of zero and forceable killing containers with no wait. + // #21874 reset := podmanTest.Podman([]string{"system", "reset", "--force"}) - reset.WaitWithDefaultTimeout() + reset.WaitWithTimeout(9) Expect(reset).Should(ExitCleanly()) session2 := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "top"})