-
Notifications
You must be signed in to change notification settings - Fork 39k
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
Make connection lost retryable in webhook #117251
Conversation
Hi @linxiulei. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/ok-to-test |
/triage accepted |
/retest |
/assign |
I knew there was some history here #109022 |
@@ -62,7 +62,7 @@ type GenericWebhook struct { | |||
// Otherwise it returns false for an immediate fail. | |||
func DefaultShouldRetry(err error) bool { | |||
// these errors indicate a transient error that should be retried. | |||
if utilnet.IsConnectionReset(err) || apierrors.IsInternalError(err) || apierrors.IsTimeout(err) || apierrors.IsTooManyRequests(err) { | |||
if utilnet.IsConnectionReset(err) || utilnet.IsConnectionLost(err) || apierrors.IsInternalError(err) || apierrors.IsTimeout(err) || apierrors.IsTooManyRequests(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.
The only retryable operations should be those that are idempotent or those that the error indicate that there is no risk to retry, IsConnectionLost means that the ping frame was not answered and is a connection level error that impacts all in-flight requests
https://cs.opensource.google/go/x/net/+/master:http2/transport.go
It doesn't seem safe to retry on this 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.
I am not too sure about if it's idempotent but I do see some similarity between IsConnectionReset and IsConnectionLost.
Anyway, is it safe to make it retryable just for webhook authentication since it's idempotent (ie. review token)? cc @liggitt
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.
Agree with IsConnectionReset, since this can be sent after the server processed some data.
Jordan know better the mechanics of the webhooks, if all operations are idempotent then +1 to retry, otherwise we should alos remove the IsConnectionReset IMHO
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.
authn and authz webhooks are safe to retry
admission webhooks are generally safe to retry, are already retried at a higher level when there's an etcd write conflict, and provide a uid in the review body so a webhook that cared about idempotence (because it had side effects it wanted to minimize) could detect a retry
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.
IIUC, only authn & authz use DefaultShouldRetry
https://sourcegraph.com/github.com/kubernetes/kubernetes@b790933e8aefdac194ba3c199b5e552a94107950/-/blob/staging/src/k8s.io/apiserver/pkg/util/webhook/webhook.go?L63%3A6=#tab=references
/lgtm |
/lgtm |
LGTM label has been added. Git tree hash: 413b6ae0b9216528683e9a28f7ad1e046f3ca674
|
@@ -47,6 +48,11 @@ func IsConnectionReset(err error) bool { | |||
return false | |||
} | |||
|
|||
// Returns if the given err is "http2: client connection lost" error. | |||
func IsHTTP2ConnectionLost(err error) bool { | |||
return err != nil && strings.Contains(err.Error(), "http2: client connection lost") |
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 we're going to just match error strings, shouldn't we have a test that notices if the go string changes and breaks this method?
https://github.com/golang/net/blob/master/http2/transport.go#L1134
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.
I really wish we could be more robust here :-/
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.
@neild how do you feel about exposing the error in golang?
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.
I really wish we could be more robust here :-/
hmm, the test setup would be painful to set up a http2 server and figure out a way to fail the ping health check. OTOH, I feel the possibility of change the error message in golang is extremely low.
Exposing the error in golang is much feasible
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.
the test setup would be painful to set up a http2 server and figure out a way to fail the ping health check.
we do have that test
func TestReconnectBrokenTCP(t *testing.T) { |
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.
Thanks, it makes things easier. PTAL!
/lgtm |
LGTM label has been added. Git tree hash: 3627aff8f08166b94ba412ce5d07349bbd07e5f0
|
When a http2 connection dies due to ping timeout, http2 client gets an error of "http2: client connection lost". This is similar to ConnectionReset case so it should be retryable. Signed-off-by: Eric Lin <exlin@google.com>
/retest |
/lgtm |
LGTM label has been added. Git tree hash: 0c2f8024859925eed910d52f069599325af53abb
|
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, linxiulei 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 |
When a http2 connection dies due to ping timeout, http2 client gets an error of "http2: client connection lost". This is similar to ConnectionReset case so it should be retryable.
What type of PR is this?
/kind bug
What this PR does / why we need it:
This PR improves resilience of webhook function in kube-apiserver by retrying requests failed on dead tcp connections.
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: