From 11c405fc854d17db98929771c1270300a5293929 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 20 Apr 2021 19:56:51 -0700 Subject: [PATCH] ensure file handles are released --- weed/filesys/file.go | 2 +- weed/filesys/filehandle.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/weed/filesys/file.go b/weed/filesys/file.go index 5fb4d8d11..bb57988cd 100644 --- a/weed/filesys/file.go +++ b/weed/filesys/file.go @@ -257,7 +257,7 @@ func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { func (file *File) Forget() { t := util.NewFullPath(file.dir.FullPath(), file.Name) glog.V(4).Infof("Forget file %s", t) - file.wfs.ReleaseHandle(t, 0) + file.wfs.ReleaseHandle(t, fuse.HandleID(t.AsInode())) } func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, err error) { diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 3f4ee69f4..27ffab6e1 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -200,13 +200,7 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err fh.f.isOpen-- - if fh.f.isOpen < 0 { - glog.V(0).Infof("Release reset %s open count %d => %d", fh.f.Name, fh.f.isOpen, 0) - fh.f.isOpen = 0 - return nil - } - - if fh.f.isOpen == 0 { + if fh.f.isOpen <= 0 { fh.f.entry = nil fh.entryViewCache = nil fh.reader = nil @@ -214,6 +208,12 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err fh.f.wfs.ReleaseHandle(fh.f.fullpath(), fuse.HandleID(fh.handle)) } + if fh.f.isOpen < 0 { + glog.V(0).Infof("Release reset %s open count %d => %d", fh.f.Name, fh.f.isOpen, 0) + fh.f.isOpen = 0 + return nil + } + return nil }