From b80d49830454c48bcb35be4668123e9aeeba761d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 29 Dec 2020 18:57:41 +0000 Subject: [PATCH] vfs: fix file leaks with --vfs-cache-mode full and --buffer-size 0 Before this change using --vfs-cache-mode full and --buffer-size 0 together caused the vfs downloader to open more and more downloaders. This is fixed by introducing a minimum size of 1M for the window to look for an existing downloader. Fixes #4892 --- vfs/vfscache/downloaders/downloaders.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vfs/vfscache/downloaders/downloaders.go b/vfs/vfscache/downloaders/downloaders.go index 190d38117..9973d0cef 100644 --- a/vfs/vfscache/downloaders/downloaders.go +++ b/vfs/vfscache/downloaders/downloaders.go @@ -26,6 +26,9 @@ const ( backgroundKickerInterval = 5 * time.Second // maximum number of errors before declaring dead maxErrorCount = 10 + // If a downloader is within this range or --buffer-size + // whichever is the larger, we will reuse the downloader + minWindow = 1024 * 1024 ) // Item is the interface that an item to download must obey @@ -327,6 +330,11 @@ func (dls *Downloaders) _ensureDownloader(r ranges.Range) (err error) { r.Size = 0 } + // If buffer size is less than minWindow then make it that + if window < minWindow { + window = minWindow + } + var dl *downloader // Look through downloaders to find one in range // If there isn't one then start a new one