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

🐛 Fix webhook write response error for broken HTTP connection #1930

Merged

Conversation

FillZpp
Copy link
Contributor

@FillZpp FillZpp commented Jun 11, 2022

Signed-off-by: FillZpp FillZpp.pub@gmail.com

Fix webhook write response error for broken HTTP connection

fixes #1829
fixes issue from slack
fixes issue from slack

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 11, 2022
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 11, 2022
@FillZpp
Copy link
Contributor Author

FillZpp commented Jun 11, 2022

/cc @alvaroaleman @joelanford

// it should not have problem to be marshalled into bytes.
// The error here is probably caused by the abnormal HTTP connection,
// e.g., broken pipe, so we can only write the error response once,
// to avoid endless circular calling.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endless circular calling, why would that happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the connection has broken, it will run into a dead loop:

  1. json.NewEncoder(w).Encode(ar) failed because of broken pipe
  2. call wh.writeResponse(w, Errored(http.StatusInternalServerError, err))
  3. call wh.writeAdmissionResponse(w, v1.AdmissionReview{Response: &response.AdmissionResponse})
  4. again json.NewEncoder(w).Encode(ar) failed because of broken pipe
  5. ...

Copy link
Contributor Author

@FillZpp FillZpp Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alvaroaleman WDYT :)
User issues can be found on the top of this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the explanation. Looks good to me, but can we add a test with a broken io.Writer to test this scenario we are fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emm.. Sure, let me see how to reproduce or mock the broken error in unit-test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added.

Signed-off-by: FillZpp <FillZpp.pub@gmail.com>
@FillZpp FillZpp force-pushed the fix-webhook-write-response branch from 57eecbc to efcc115 Compare June 14, 2022 11:38
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 14, 2022
@FillZpp
Copy link
Contributor Author

FillZpp commented Jun 14, 2022

/retest

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
/lgtm
/approve
/cherrypick release-0.12

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 14, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, FillZpp

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 14, 2022
@k8s-ci-robot k8s-ci-robot merged commit a759a0d into kubernetes-sigs:master Jun 14, 2022
@k8s-ci-robot k8s-ci-robot added this to the v0.10.x milestone Jun 14, 2022
@alvaroaleman
Copy link
Member

/cherrypick release-0.12

@k8s-infra-cherrypick-robot

@alvaroaleman: new pull request created: #1931

In response to this:

/cherrypick release-0.12

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.

@yuzliu
Copy link

yuzliu commented Jun 14, 2022

@FillZpp awesome information. Do you happen to know why api server drop http connections? I start to observe this issue in clusters with Kubernetes 1.20 deployed and very curious to know what caused that.

@FillZpp
Copy link
Contributor Author

FillZpp commented Jun 15, 2022

@FillZpp awesome information. Do you happen to know why api server drop http connections? I start to observe this issue in clusters with Kubernetes 1.20 deployed and very curious to know what caused that.

I believe that if the apiserver container/pod has been restarted or recreated during the request to webhook, then webhook will get the broken pipe error when it tries to write response back to the connection. But I'm not sure in which cases apiserver will close or lose the connection if it remains running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

circular dependency between writeResponse & writeAdmissionResponse
5 participants