Skip to content

Commit

Permalink
Add a very long overall timeout for Autopilot downloads
Browse files Browse the repository at this point in the history
This will ensure that the download will fail at some point, even if the
remote server is artificially slow.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
  • Loading branch information
twz123 committed Sep 26, 2024
1 parent 1a54f6c commit 8cb867f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/autopilot/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"hash"
"io"
"path/filepath"
"time"

internalhttp "github.com/k0sproject/k0s/internal/http"
"github.com/k0sproject/k0s/internal/pkg/file"
Expand Down Expand Up @@ -86,6 +87,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.
if err = internalhttp.Download(ctx, d.config.URL, io.MultiWriter(targets...), downloadOpts...); err != nil {
return fmt.Errorf("download failed: %w", err)
Expand Down

0 comments on commit 8cb867f

Please sign in to comment.