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
This commit is contained in:
Nick Craig-Wood 2020-12-29 18:57:41 +00:00
parent 757e696a6b
commit b80d498304

View File

@ -26,6 +26,9 @@ const (
backgroundKickerInterval = 5 * time.Second backgroundKickerInterval = 5 * time.Second
// maximum number of errors before declaring dead // maximum number of errors before declaring dead
maxErrorCount = 10 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 // 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 r.Size = 0
} }
// If buffer size is less than minWindow then make it that
if window < minWindow {
window = minWindow
}
var dl *downloader var dl *downloader
// Look through downloaders to find one in range // Look through downloaders to find one in range
// If there isn't one then start a new one // If there isn't one then start a new one