Browse Source

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.
pull/7627/head
chrislu 6 days ago
parent
commit
c31ec80a93
  1. 18
      weed/filer/reader_cache.go

18
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()

Loading…
Cancel
Save