From aa4e2c326295e722985dbdf1d5c7849bf8593420 Mon Sep 17 00:00:00 2001 From: Ting Yuan Date: Mon, 1 Nov 2021 14:26:57 +0800 Subject: [PATCH] Fix goroutine leak bug in DoDownloadTimeout Signed-off-by: Ting Yuan --- dfget/core/downloader/downloader.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dfget/core/downloader/downloader.go b/dfget/core/downloader/downloader.go index a0bc1698f..e0157b197 100644 --- a/dfget/core/downloader/downloader.go +++ b/dfget/core/downloader/downloader.go @@ -53,7 +53,12 @@ func DoDownloadTimeout(downloader Downloader, timeout time.Duration) error { var ch = make(chan error) go func() { - ch <- downloader.Run(ctx) + select { + case <- ctx.Done(): + return + case ch <- downloader.Run(ctx): + return + } }() defer cancel()