From 1a51ccef668a7352554c9f99f0b63398bb47738b Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Sep 2024 14:31:01 +0200 Subject: [PATCH] Add a very long overall timeout for Autopilot downloads This will ensure that the download will fail at some point, even if the remote server is artificially slow. Signed-off-by: Tom Wieczorek --- pkg/autopilot/download/downloader.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/autopilot/download/downloader.go b/pkg/autopilot/download/downloader.go index 4300b1549d1e..7f8fbc147884 100644 --- a/pkg/autopilot/download/downloader.go +++ b/pkg/autopilot/download/downloader.go @@ -23,6 +23,7 @@ import ( "hash" "io" "path/filepath" + "time" internalhttp "github.com/k0sproject/k0s/internal/http" "github.com/k0sproject/k0s/internal/pkg/file" @@ -73,6 +74,12 @@ func (d *downloader) Download(ctx context.Context) (err error) { defer func() { err = errors.Join(err, target.Close()) }() targets = append(targets, target) + // Set a very long overall download timeout. This will ensure that the + // download will fail at some point, even if the remote server is + // artificially slow. + ctx, cancel := context.WithTimeout(ctx, 6*time.Hour) + defer cancel() + // Download from URL into targets. var fileName string if err = internalhttp.Download(ctx, d.config.URL, io.MultiWriter(targets...),