From c0b6acb10fb2ebbcae6a63e4ad6879204168601c Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 4 Dec 2025 21:55:55 -0800 Subject: [PATCH] filer: document why context.Background() is used in startCaching Add comment explaining the intentional design decision: the downloaded chunk is a shared resource that may be used by multiple concurrent readers. Using context.Background() ensures the download completes even if one reader cancels, preventing errors for other waiting readers. --- weed/filer/reader_cache.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/weed/filer/reader_cache.go b/weed/filer/reader_cache.go index f291a7e7a..d1e7226dc 100644 --- a/weed/filer/reader_cache.go +++ b/weed/filer/reader_cache.go @@ -178,6 +178,12 @@ func (s *SingleChunkCacher) startCaching() { s.cacheStartedCh <- struct{}{} // signal that we've started + // Note: We intentionally use context.Background() here, NOT a request-specific context. + // The downloaded chunk is a shared resource - multiple concurrent readers may be waiting + // for this same download to complete. If we used a request context and that request was + // cancelled, it would abort the download and cause errors for all other waiting readers. + // The download should always complete once started to serve all potential consumers. + // Lookup file ID without holding the lock urlStrings, err := s.parent.lookupFileIdFn(context.Background(), s.chunkFileId) if err != nil {