From b2800947bd6a959590c077e5a69cfbb983b304b7 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 4 Dec 2025 22:17:51 -0800 Subject: [PATCH] filer: use defer for close(done) to guarantee signal on panic Move close(s.done) to a defer statement at the start of startCaching() to ensure the completion signal is always sent, even if an unexpected panic occurs. This prevents readers from blocking indefinitely. --- weed/filer/reader_cache.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/weed/filer/reader_cache.go b/weed/filer/reader_cache.go index 2f4def8aa..0010f0386 100644 --- a/weed/filer/reader_cache.go +++ b/weed/filer/reader_cache.go @@ -175,6 +175,7 @@ func newSingleChunkCacher(parent *ReaderCache, fileId string, cipherKey []byte, func (s *SingleChunkCacher) startCaching() { s.wg.Add(1) defer s.wg.Done() + defer close(s.done) // guarantee completion signal even on panic s.cacheStartedCh <- struct{}{} // signal that we've started @@ -190,7 +191,6 @@ func (s *SingleChunkCacher) startCaching() { s.Lock() s.err = fmt.Errorf("operation LookupFileId %s failed, err: %v", s.chunkFileId, err) s.Unlock() - close(s.done) // signal completion return } @@ -212,8 +212,6 @@ func (s *SingleChunkCacher) startCaching() { atomic.StoreInt64(&s.completedTimeNew, time.Now().UnixNano()) } s.Unlock() - - close(s.done) // signal completion to all waiting readers } func (s *SingleChunkCacher) destroy() {