diff --git a/libpod/healthcheck_linux.go b/libpod/healthcheck_linux.go index 344c4a2029..e751c4e00b 100644 --- a/libpod/healthcheck_linux.go +++ b/libpod/healthcheck_linux.go @@ -137,13 +137,8 @@ func (c *Container) removeTransientFiles(ctx context.Context, isStartup bool, un stopErrors = append(stopErrors, fmt.Errorf("stopping systemd health-check timer %q: %w", timerFile, err)) } - // Reset the service before stopping it to make sure it's being removed - // on stop. serviceChan := make(chan string) serviceFile := fmt.Sprintf("%s.service", unitName) - if err := conn.ResetFailedUnitContext(ctx, serviceFile); err != nil { - logrus.Debugf("Failed to reset unit file: %q", err) - } if _, err := conn.StopUnitContext(ctx, serviceFile, "ignore-dependencies", serviceChan); err != nil { if !strings.HasSuffix(err.Error(), ".service not loaded.") { stopErrors = append(stopErrors, fmt.Errorf("removing health-check service %q: %w", serviceFile, err)) @@ -151,6 +146,12 @@ func (c *Container) removeTransientFiles(ctx context.Context, isStartup bool, un } else if err := systemdOpSuccessful(serviceChan); err != nil { stopErrors = append(stopErrors, fmt.Errorf("stopping systemd health-check service %q: %w", serviceFile, err)) } + // Reset the service after stopping it to make sure it's being removed, systemd keep failed transient services + // around in its state. We do not care about the error and we need to ensure to reset the state so we do not + // leak resources forever. + if err := conn.ResetFailedUnitContext(ctx, serviceFile); err != nil { + logrus.Debugf("Failed to reset unit file: %q", err) + } return errorhandling.JoinErrors(stopErrors) }