-
Notifications
You must be signed in to change notification settings - Fork 39.3k
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
Webhook: handle error when calling wait.ExponentialBackoff #95874
Conversation
@tkashem: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @deads2k |
/retest |
3 similar comments
/retest |
/retest |
/retest |
if ctx.Err() != nil { | ||
// we timed out or were cancelled, we should not retry | ||
return true, err | ||
return true, webhookErr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the context fails, the webhookErr could be nil and we would still want to fail, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if context fails, we should return ctx.Err()
25c7395
to
49f5387
Compare
/retest |
} | ||
return true, nil | ||
}) | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch{
// if we have a webhook error, it's the most important
case webhookErr != nil:
return webhookErr
// if we have a deadline exceeded or cancelled, then that 's got priority over timeouts.
case ctx.Err() != nil:
return ctx.Err()
// if the wait returned an error, but we didn't get a webhook error, it should be timeout and return that
case err != nil:
return err
// if nothing had an error, then return nil
default:
return nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k If the context gets canceled or times out then wait.ExponentialBackoff
returns the context error to us via err
. So either ctx
error or wait.Timeout
error is returned. I don't think we need to check for ctx.Err() != nil
in the switch.
I added the switch statement as suggested.
Also, in the current implementation, we call the webhookFn
first and then check for ctx.Error
. I think checking if the context has timed out first before calling the webhookFn
function is more correct.
err := wait.ExponentialBackoff(backoff, func() (bool, error) {
if ctx.Err() != nil {
// we timed out or were cancelled, we should not retry
return true, ctx.Err()
}
webhookErr = webhookFn()
I added two unit tests to verify:
- webhookErr is more important than
ctx.Err()
- If the context is already canceled, there is no need to call the
webhookFn
function.
49f5387
to
e1415cf
Compare
/retest |
e1415cf
to
fbafc3a
Compare
return true, err | ||
} | ||
if shouldRetry(err) { | ||
var webhookErr error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a comment for future generations
// having a webhook error allows us to track the last actual webhook error for requests that are later cancelled or time out
/lgtm |
/hold let's get that nit on that comment. It may be not be super obvious. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, tkashem The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
- Inside WithExponentialBackoff function, handle error returned by wait.ExponentialBackoff. - Ensure that the wait time is bound to the given context.
fbafc3a
to
f8e35de
Compare
/lgtm |
/priority important-soon |
/retest |
@tkashem: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/retest |
…4-upstream-release-1.19 Automated cherry pick of #95874: Webhook: handle error when calling wait.ExponentialBackoff
What type of PR is this?
/kind bug
What this PR does / why we need it:
Inside
WithExponentialBackoff
function, handle error returned bywait.ExponentialBackoff
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: