google/stenographer

filecache Close set to nil before Close

fming188 opened this issue · 1 comments

Hi,
I was trying to track down an issue that when the disk usage exceeded limit, the stenographer removes all cache file instead of enough just to be below the limit. Strace show that the actual syscall of close() is about two minutes after the unlink of the file. During the two minutes, stenographer makes repeated attempts to remove more files and eventually deleted all of the cache.

Found the last function in filecache.go, the cf.f is set to nil before Close. I have never coded in go, but this looks unusual. Changes the code to

func (cf *CachedFile) closeFile() error {
if cf.f == nil {
v(3, "Close of already-closed file %q ignored", cf.filename)
return nil
}
v(2, "Closing %q", cf.filename)
cf.cache.opened--
defer cf.nilFile()
return cf.f.Close()
}

func (cf *CachedFile) nilFile() {
cf.f = nil
}

The problem is gone.

Ming

Oops! That's not intentional :P

Pull #188 to fix, thanks for both reporting and clearly debugging the issue!