From 559dfb82a241184dc0c7709767a31ee7ba8ffe99 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Tue, 3 Sep 2024 19:14:21 +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 --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/harvester/go-common/sys/systemd-dbus.go | 2 ++ vendor/modules.txt | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d319229..b4fd2a2 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ replace ( require ( github.com/ehazlett/simplelog v0.0.0-20200226020431-d374894e92a4 github.com/godbus/dbus/v5 v5.1.0 - github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca + github.com/harvester/go-common v0.0.0-20240903083523-9576346cda75 github.com/mudler/yip v1.1.0 github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.16.0 diff --git a/go.sum b/go.sum index fea3d26..1422809 100644 --- a/go.sum +++ b/go.sum @@ -177,8 +177,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca h1:gUgeAQ9NSFEBqVkKJxTmbhbob/6CWu/iDlD4V40IpdU= -github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca/go.mod h1:UNh9xAFqna6F2Fk4m4TTNWV0xaORlFwH7B+DepHT/gI= +github.com/harvester/go-common v0.0.0-20240903083523-9576346cda75 h1:zzh4ZWH1+4MPb9xwB0uhKfUF19OEZOFJJlMkKgKEyv8= +github.com/harvester/go-common v0.0.0-20240903083523-9576346cda75/go.mod h1:UNh9xAFqna6F2Fk4m4TTNWV0xaORlFwH7B+DepHT/gI= github.com/harvester/webhook v0.1.4 h1:6g5MkYXlGm0wABQ/Dm8g5sM7WAtPq2aiWOH9wmf2vUQ= github.com/harvester/webhook v0.1.4/go.mod h1:vfRPB26WHSPxMF/ONpUVzaEaewTUxpP9qAqu1ZyonR0= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/vendor/github.com/harvester/go-common/sys/systemd-dbus.go b/vendor/github.com/harvester/go-common/sys/systemd-dbus.go index b5e580f..e445464 100644 --- a/vendor/github.com/harvester/go-common/sys/systemd-dbus.go +++ b/vendor/github.com/harvester/go-common/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) diff --git a/vendor/modules.txt b/vendor/modules.txt index 421181f..36a39ab 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -80,7 +80,7 @@ github.com/google/uuid # github.com/gorilla/mux v1.8.0 ## explicit; go 1.12 github.com/gorilla/mux -# github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca +# github.com/harvester/go-common v0.0.0-20240903083523-9576346cda75 ## explicit; go 1.22 github.com/harvester/go-common/common github.com/harvester/go-common/files