From 11544a62aa6c67aed0ecaaa3d0c5f63e9437638e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 8 Oct 2023 12:17:08 -0700 Subject: [PATCH] fix: upon write failure on disk journal close the file properly (#18183) close the file properly before dereferencing *os.File, this can silently leak fd's in rare cases. This PR fixes this properly. --- cmd/tier-journal.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/tier-journal.go b/cmd/tier-journal.go index 2f8037011..ba965fc73 100644 --- a/cmd/tier-journal.go +++ b/cmd/tier-journal.go @@ -195,6 +195,10 @@ func (jd *tierDiskJournal) addEntry(je jentry) error { defer jd.Unlock() _, err = jd.file.Write(b) if err != nil { + // Do not leak fd here, close the file properly. + Fdatasync(jd.file) + _ = jd.file.Close() + jd.file = nil // reset to allow subsequent reopen when file/disk is available. } return err