Skip to content

Commit

Permalink
Bug 2090680: pkg/cvo/updatepayload.go: timeout payload retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
jottofar committed Dec 20, 2022
1 parent af08109 commit 6df3fbc
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions pkg/cvo/updatepayload.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,12 @@ func (r *payloadRetriever) RetrievePayload(ctx context.Context, update configv1.
if index := strings.LastIndex(update.Image, "@"); index != -1 {
releaseDigest = update.Image[index+1:]
}
verifyCtx := ctx

// if 'force' specified, ensure call to verify payload signature times out well before parent context
// to allow time to perform forced update
if update.Force {
timeout := time.Minute * 2
if deadline, deadlineSet := ctx.Deadline(); deadlineSet {
timeout = time.Until(deadline) / 2
}
klog.V(2).Infof("Forced update so reducing payload signature verification timeout to %s", timeout)
var cancel context.CancelFunc
verifyCtx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}

if err := r.verifier.Verify(verifyCtx, releaseDigest); err != nil {
// set up a new context with reasonable timeout for signature and payload retrieval
retrieveCtx, cancel := context.WithTimeout(ctx, time.Minute*4)
defer cancel()

if err := r.verifier.Verify(retrieveCtx, releaseDigest); err != nil {
vErr := &payload.UpdateError{
Reason: "ImageVerificationFailed",
Message: fmt.Sprintf("The update cannot be verified: %v", err),
Expand All @@ -122,7 +112,7 @@ func (r *payloadRetriever) RetrievePayload(ctx context.Context, update configv1.

// download the payload to the directory
var err error
info.Directory, err = r.targetUpdatePayloadDir(ctx, update)
info.Directory, err = r.targetUpdatePayloadDir(retrieveCtx, update)
if err != nil {
return PayloadInfo{}, &payload.UpdateError{
Reason: "UpdatePayloadRetrievalFailed",
Expand Down

0 comments on commit 6df3fbc

Please sign in to comment.