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.
This commit is contained in:
Harshavardhana 2023-10-08 12:17:08 -07:00 committed by GitHub
parent 18550387d5
commit 11544a62aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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