From dd46e7a3eb6728cd77bd425867a173a2f96c66dd Mon Sep 17 00:00:00 2001 From: Li Wei Date: Mon, 6 Mar 2023 21:09:31 +0800 Subject: [PATCH] fix: crash caused by non-resumable http download resources (#97) --- internal/protocol/http/fetcher.go | 2 +- internal/protocol/http/fetcher_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 7d4d8a66..cb8ae1ec 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -250,7 +250,7 @@ func (f *Fetcher) filepath() string { func (f *Fetcher) fetch() { f.ctx, f.cancel = context.WithCancel(context.Background()) eg, _ := errgroup.WithContext(f.ctx) - for i := 0; i < f.meta.Opts.Extra.(*fhttp.OptsExtra).Connections; i++ { + for i := 0; i < len(f.chunks); i++ { i := i eg.Go(func() error { return f.fetchChunk(i) diff --git a/internal/protocol/http/fetcher_test.go b/internal/protocol/http/fetcher_test.go index cf4f35ed..def01f3e 100644 --- a/internal/protocol/http/fetcher_test.go +++ b/internal/protocol/http/fetcher_test.go @@ -79,6 +79,7 @@ func TestFetcher_DownloadChunked(t *testing.T) { defer listener.Close() // chunked编码下载 downloadNormal(listener, 1, t) + downloadNormal(listener, 2, t) } func TestFetcher_DownloadPost(t *testing.T) {