From a19d4087cc4552f5d74e202470d4937f7c72a24f Mon Sep 17 00:00:00 2001 From: Thomas Gosteli Date: Thu, 7 Nov 2024 10:19:15 +0100 Subject: [PATCH] fix(defrag): close temp file in case of error Signed-off-by: Thomas Gosteli --- server/storage/backend/backend.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/storage/backend/backend.go b/server/storage/backend/backend.go index c29993ab43b..526fef7eaf8 100644 --- a/server/storage/backend/backend.go +++ b/server/storage/backend/backend.go @@ -499,6 +499,15 @@ func (b *backend) defrag() error { tdbp := temp.Name() tmpdb, err := bolt.Open(tdbp, 0600, &options) if err != nil { + temp.Close() + if err := os.Remove(temp.Name()); err != nil && b.lg != nil { + b.lg.Error( + "failed to remove temporary file", + zap.String("path", temp.Name()), + zap.Error(err), + ) + } + return err }