From 11ea70b4ff3efecd0aa30a4468c41b14196c8936 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Tue, 3 Sep 2024 17:51:36 +1000 Subject: [PATCH] fix: ensure dbus connections are closed in (Try)RestartService Related issue: https://github.com/harvester/harvester/issues/6484 Signed-off-by: Tim Serong --- sys/systemd-dbus.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/systemd-dbus.go b/sys/systemd-dbus.go index b5e580f..e445464 100644 --- a/sys/systemd-dbus.go +++ b/sys/systemd-dbus.go @@ -15,6 +15,7 @@ func RestartService(unit string) error { logrus.Errorf("Failed to create new connection for systemd. err: %v", err) return err } + defer conn.Close() responseChan := make(chan string, 1) if _, err := conn.RestartUnitContext(ctx, unit, "fail", responseChan); err != nil { logrus.Errorf("Failed to restart service %s. err: %v", unit, err) @@ -32,6 +33,7 @@ func TryRestartService(unit string) error { logrus.Errorf("Failed to create new connection for systemd. err: %v", err) return err } + defer conn.Close() responseChan := make(chan string, 1) if _, err := conn.TryRestartUnitContext(ctx, unit, "fail", responseChan); err != nil { logrus.Errorf("Failed to restart service %s. err: %v", unit, err)