google / stenographer

Stenographer is a packet capture solution which aims to quickly spool all packets to disk, then provide simple, fast access to subsets of those packets. Discussion/announcements at stenographer@googlegroups.com
Apache License 2.0
1.79k stars 238 forks source link

filecache Close set to nil before Close #187

Closed fming188 closed 6 years ago

fming188 commented 6 years ago

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

gconnell commented 6 years ago

Oops! That's not intentional :P

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