Skip to content

Commit

Permalink
Merge pull request etcd-io#18854 from ghouscht/backport-defrag-close-…
Browse files Browse the repository at this point in the history
…temp-3.5

[3.5] fix(defrag): close temp file in case of error
  • Loading branch information
ahrtr authored Nov 9, 2024
2 parents d770310 + b2ba488 commit 4726460
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/mvcc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4726460

Please sign in to comment.