From 006f78b70b458ca55c66f9f50692cbd9996fb5ad Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 8 Apr 2020 22:31:19 -0700 Subject: [PATCH] make a copy of request data to avoid concurrency issues --- weed/filesys/filehandle.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 18544a7f1..ea53ed4c0 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -114,21 +114,23 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) { func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error { // write the request to volume servers + data := make([]byte, len(req.Data)) + copy(data, req.Data) - fh.f.entry.Attributes.FileSize = uint64(max(req.Offset+int64(len(req.Data)), int64(fh.f.entry.Attributes.FileSize))) + fh.f.entry.Attributes.FileSize = uint64(max(req.Offset+int64(len(data)), int64(fh.f.entry.Attributes.FileSize))) // glog.V(0).Infof("%v write [%d,%d)", fh.f.fullpath(), req.Offset, req.Offset+int64(len(req.Data))) - chunks, err := fh.dirtyPages.AddPage(req.Offset, req.Data) + chunks, err := fh.dirtyPages.AddPage(req.Offset, data) if err != nil { - glog.Errorf("%v write fh %d: [%d,%d): %v", fh.f.fullpath(), fh.handle, req.Offset, req.Offset+int64(len(req.Data)), err) + glog.Errorf("%v write fh %d: [%d,%d): %v", fh.f.fullpath(), fh.handle, req.Offset, req.Offset+int64(len(data)), err) return fuse.EIO } - resp.Size = len(req.Data) + resp.Size = len(data) if req.Offset == 0 { // detect mime type - detectedMIME := mimetype.Detect(req.Data) + detectedMIME := mimetype.Detect(data) fh.contentType = detectedMIME.String() if ext := path.Ext(fh.f.Name); ext != detectedMIME.Extension() { fh.contentType = mime.TypeByExtension(ext) @@ -159,6 +161,8 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err } fh.f.entryViewCache = nil fh.f.reader = nil + fh.dirtyPages = nil + fh.f = nil return nil }