From 2a88da4de757630a7d35779867f24c66c71ae7a9 Mon Sep 17 00:00:00 2001 From: Henco Appel Date: Tue, 2 Apr 2024 16:31:40 +0100 Subject: [PATCH] fix: always close volume file (#4530) (#5459) If sync fails then close is never called. We should always be calling close on the file. Co-authored-by: Hendrik Appel --- weed/storage/backend/disk_file.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/weed/storage/backend/disk_file.go b/weed/storage/backend/disk_file.go index 050ded613..68ffbd7e7 100644 --- a/weed/storage/backend/disk_file.go +++ b/weed/storage/backend/disk_file.go @@ -81,13 +81,20 @@ func (df *DiskFile) Close() error { if df.File == nil { return nil } - if err := df.Sync(); err != nil { - return err + err := df.Sync() + var err1 error + if df.File != nil { + // always try to close + err1 = df.File.Close() } - if err := df.File.Close(); err != nil { + // assume closed + df.File = nil + if err != nil { return err } - df.File = nil + if err1 != nil { + return err1 + } return nil }