Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel downloadRequest when timeout without downloadURL #5329

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/5329-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cancel downloadRequest when timeout without downloadURL
13 changes: 10 additions & 3 deletions pkg/cmd/util/downloadrequest/downloadrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
// ErrNotFound is exported for external packages to check for when a file is
// not found
var ErrNotFound = errors.New("file not found")
var ErrDownloadRequestDownloadURLTimeout = errors.New("download request download url timeout, check velero server logs for errors. backup storage location may not be available")

func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name string, kind velerov1api.DownloadTargetKind, w io.Writer, timeout time.Duration, insecureSkipTLSVerify bool, caCertFile string) error {
uuid, err := uuid.NewRandom()
Expand All @@ -58,7 +59,14 @@ func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name strin
defer cancel()

key := kbclient.ObjectKey{Name: created.Name, Namespace: namespace}
timeStreamFirstCheck := time.Now()
downloadUrlTimeout := false
checkFunc := func() {
// if timeout has been reached, cancel request
if time.Now().After(timeStreamFirstCheck.Add(timeout)) {
downloadUrlTimeout = true
cancel()
}
updated := &velerov1api.DownloadRequest{}
if err := kbClient.Get(ctx, key, updated); err != nil {
return
Expand All @@ -77,9 +85,8 @@ func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name strin
}

wait.Until(checkFunc, 25*time.Millisecond, ctx.Done())

if created.Status.DownloadURL == "" {
return ErrNotFound
if downloadUrlTimeout {
return ErrDownloadRequestDownloadURLTimeout
}

var caPool *x509.CertPool
Expand Down