From 03f95ee096b710569bd059c645cb15319edf27fb Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 12 Jun 2017 00:05:04 +0200 Subject: [PATCH] Fix directory file descriptor leak. --- compact.go | 4 ++++ db.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/compact.go b/compact.go index ca646a084..7799b640f 100644 --- a/compact.go +++ b/compact.go @@ -300,6 +300,8 @@ func (c *compactor) write(uid ulid.ULID, blocks ...Block) (err error) { if err != nil { return errors.Wrap(err, "sync block dir") } + defer df.Close() + if err := fileutil.Fsync(df); err != nil { return errors.Wrap(err, "sync block dir") } @@ -583,6 +585,8 @@ func renameFile(from, to string) error { if err != nil { return err } + defer pdir.Close() + if err = fileutil.Fsync(pdir); err != nil { return err } diff --git a/db.go b/db.go index fe35a348d..e0e8ff173 100644 --- a/db.go +++ b/db.go @@ -386,6 +386,8 @@ func retentionCutoff(dir string, mint int64) (bool, error) { if err != nil { return false, errors.Wrapf(err, "open directory") } + defer df.Close() + dirs, err := blockDirs(dir) if err != nil { return false, errors.Wrapf(err, "list block dirs %s", dir)