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

use context to check client closed instead of http.CloseNotifier in processing watch request #85408

Merged

Conversation

answer1991
Copy link
Contributor

@answer1991 answer1991 commented Nov 18, 2019

What type of PR is this?

/kind bug

What this PR does / why we need it:

Use context to check client closed instead of http.CloseNotifier. For two reasons:

  1. http.CloseNotifier is deprecated.
  2. http.CloseNotifier will cost 1 more goroutine if proto is HTTP/2.x .

https://github.com/golang/go/blob/2bde3c13f6e31662c682f1b5830c5e3fd9f5494c/src/net/http/h2_bundle.go#L6152

Which issue(s) this PR fixes:

Related issue: #84001

Special notes for your reviewer:

None

Does this PR introduce a user-facing change?:

Use context to check client closed instead of http.CloseNotifier in processing watch request which will reduce 1 goroutine for each request if proto is HTTP/2.x .

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

None

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 18, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @answer1991. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 18, 2019
@answer1991
Copy link
Contributor Author

cc @wojtek-t PTAL

@answer1991 answer1991 force-pushed the feature/reduce-watch-goruntine branch 2 times, most recently from 0bbaed6 to 66b992b Compare November 18, 2019 08:33
@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 Nov 18, 2019
@mars1024
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 18, 2019
@wojtek-t wojtek-t added this to the v1.18 milestone Nov 18, 2019
@answer1991
Copy link
Contributor Author

/test pull-kubernetes-bazel-test

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 18, 2019
@k8s-ci-robot k8s-ci-robot removed the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 18, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 18, 2019
@answer1991
Copy link
Contributor Author

/test pull-kubernetes-integration

}
// Use context to check client closed instead of http.CloseNotifier.
// Since http.CloseNotifier is deprecated, what's worse,
// http.CloseNotifier will cost 1 more goruntine if proto is HTTP/2.x.
Copy link

@riking riking Nov 18, 2019

Choose a reason for hiding this comment

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

A lot of this comment belongs in the commit message, not in the code. The code comment could be // Use context instead of CloseNotifier as it's more efficient, or simply nothing as there's not anything particularly tricky about this. (The tricky part is knowing to do it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I have removed comment. Thanks!

// Since http.CloseNotifier is deprecated, what's worse,
// http.CloseNotifier will cost 1 more goruntine if proto is HTTP/2.x.
ctx := req.Context()
done := ctx.Done()
Copy link
Member

Choose a reason for hiding this comment

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

nit: squash the two lines above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@answer1991
Copy link
Contributor Author

cc @lavalamp

t.Fatalf("Unexpected response: %#v\n%s", response, string(b))
}

if err := response.Body.Close(); err != nil {
Copy link

@riking riking Nov 19, 2019

Choose a reason for hiding this comment

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

perhaps add a comment here saying // Close response without reading it to cause a cancel on the server

EDIT: Also, I am aware that this Github approval does not count as a k8s LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added comment, thanks

@answer1991
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce

@lavalamp
Copy link
Member

/lgtm
/approve

Many thanks for the test.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: answer1991, lavalamp

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 Nov 20, 2019
@k8s-ci-robot k8s-ci-robot merged commit bf8c276 into kubernetes:master Nov 23, 2019
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. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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.

None yet

7 participants