From c31ec80a930cb4bab833eb093e933864564fdf43 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 4 Dec 2025 22:58:15 -0800 Subject: [PATCH] filer: prioritize done channel over context cancellation If data is already available (done channel closed), return it even if the reader's context is also cancelled. This avoids unnecessary errors when the download has already completed. --- weed/filer/reader_cache.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/weed/filer/reader_cache.go b/weed/filer/reader_cache.go index 8f2b66231..66cbac1e3 100644 --- a/weed/filer/reader_cache.go +++ b/weed/filer/reader_cache.go @@ -240,13 +240,21 @@ func (s *SingleChunkCacher) readChunkAt(ctx context.Context, buf []byte, offset s.wg.Add(1) defer s.wg.Done() - // Wait for download to complete, but allow reader cancellation + // Wait for download to complete, but allow reader cancellation. + // Prioritize checking done first - if data is already available, + // return it even if context is also cancelled. select { case <-s.done: - // Download completed - case <-ctx.Done(): - // Reader cancelled - download continues for other readers - return 0, ctx.Err() + // Download already completed, proceed immediately + default: + // Download not complete, wait for it or context cancellation + select { + case <-s.done: + // Download completed + case <-ctx.Done(): + // Reader cancelled while waiting - download continues for other readers + return 0, ctx.Err() + } } s.Lock()