From 76ddfb74604231e6c3dae314ba2a20f281a1af42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Thu, 26 Oct 2023 15:36:38 +0200 Subject: [PATCH] bugfix: Fix panic due to early closure of database This regression was introduced in f41de3b42e2f69f57eea33cd6f6fae49b7e26963 --- windows-agent/internal/proservices/proservices.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/windows-agent/internal/proservices/proservices.go b/windows-agent/internal/proservices/proservices.go index ec79c3ec6..84f17c59d 100644 --- a/windows-agent/internal/proservices/proservices.go +++ b/windows-agent/internal/proservices/proservices.go @@ -90,7 +90,13 @@ func New(ctx context.Context, args ...Option) (s Manager, err error) { if err != nil { return s, err } - defer db.Close(ctx) + defer func() { + // Close DB if we return error + // Otherwise, it'll be closed in the call to Manager.Stop + if err != nil { + db.Close(ctx) + } + }() if err := conf.UpdateRegistrySettings(ctx, opts.cacheDir, db); err != nil { log.Warningf(ctx, "Could not update registry settings: %v", err)