From b2ba488269f1f081667c0ae11fe775bb080f9357 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/mvcc/backend/backend.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/mvcc/backend/backend.go b/server/mvcc/backend/backend.go index d04126d94ae..d278e2be097 100644 --- a/server/mvcc/backend/backend.go +++ b/server/mvcc/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 rmErr := os.Remove(temp.Name()); rmErr != nil && b.lg != nil { + b.lg.Error( + "failed to remove temporary file", + zap.String("path", temp.Name()), + zap.Error(rmErr), + ) + } + return err }