SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix(filer): avoid ReaderCache WaitGroup reuse race between reads and destroy (#10190)
Chris Luece4f42ecd0c
diff --git a/weed/filer/reader_cache.go b/weed/filer/reader_cache.goindex 224ce8d8a8..055666fd81 100644--- a/weed/filer/reader_cache.go+++ b/weed/filer/reader_cache.go@@ -116,6 +116,10 @@ func (rc *ReaderCache) ReadChunkAt(ctx context.Context, buffer []byte, fileId strc.Lock()continue}+ // Count this read on the cacher before releasing the map lock, so a+ // concurrent destroy() (error eviction here, LRU, or UnCache) cannot+ // start wg.Wait() on a zero counter while this read is about to register.+ cacher.wg.Add(1)rc.Unlock()n, err := cacher.readChunkAt(ctx, buffer, offset)if n > 0 || err != nil {@@ -157,6 +161,7 @@ func (rc *ReaderCache) ReadChunkAt(ctx context.Context, buffer []byte, fileId stgo cacher.startCaching()<-cacher.cacheStartedChrc.downloaders[fileId] = cacher+ cacher.wg.Add(1)rc.Unlock()return cacher.readChunkAt(ctx, buffer, offset)@@ -302,8 +307,8 @@ func (s *SingleChunkCacher) destroy() {// It waits for the download to complete if it's still in progress.// The ctx parameter allows the reader to cancel its wait (but the download continues// for other readers - see comment in startCaching about shared resource semantics).+// The caller must s.wg.Add(1) under the ReaderCache lock before calling; this only releases it.func (s *SingleChunkCacher) readChunkAt(ctx context.Context, buf []byte, offset int64) (int, error) {- s.wg.Add(1)defer s.wg.Done()// Wait for download to complete, but allow reader cancellation.