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

Support cancelable SPDY executor stream #103177

Merged

Conversation

arkbriar
Copy link
Contributor

@arkbriar arkbriar commented Jun 25, 2021

What type of PR is this?

/kind bug
/kind feature

What this PR does / why we need it:

Sometimes I find that even simple command like "echo something" will hang there forever when there're lots of SPDY executor streams running. In the last case, I've examined all the call stacks with debug tool and still haven't figured out why. It seems all of the streams stuck on waiting for next frame and the TCP connections were still alive then. But these streams had already been existed for over 10 minutes.

Anyway, I think it will be reasonable if some bad streams can be canceled to avoid resource leaks. So I just enhance the remotecommand.Executor interface with a method accepts a context to support cancelable SPDY executor stream.

Also test have been modified to ensure it works.

Which issue(s) this PR fixes:

Fixes kubernetes/client-go#884

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Add a method `StreamWithContext` to remotecommand.Executor to support cancelable SPDY executor stream.

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


@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. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/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 Jun 25, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @arkbriar. 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 sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 25, 2021
@arkbriar
Copy link
Contributor Author

/assign @deads2k

@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 29, 2021
@arkbriar
Copy link
Contributor Author

arkbriar commented Jul 1, 2021

/assign @liggitt

@aojea
Copy link
Member

aojea commented Jul 23, 2021

@arkbriar
Copy link
Contributor Author

should the context plumbed down to the spdy request too?
https://github.com/kubernetes/client-go/blob/ac207faedfb64acd5b99a2fb309b7044918b4dda/transport/spdy/spdy.go#L71

@aojea For stream executor interface, it's enough to have a context here.
But yes, for the dialer interface, it still needs a context to let timeout possible.
I'll fix it in this PR. 😁

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 26, 2021
@aojea
Copy link
Member

aojea commented Jul 26, 2021

should the context plumbed down to the spdy request too?
https://github.com/kubernetes/client-go/blob/ac207faedfb64acd5b99a2fb309b7044918b4dda/transport/spdy/spdy.go#L71

@aojea For stream executor interface, it's enough to have a context here.
But yes, for the dialer interface, it still needs a context to let timeout possible.
I'll fix it in this PR.

I was trying to understand if this could also fix kubernetes/kubectl#686 , but I think I was wrong, and the spdy and Dialer context are not really needed here as you correctly pointed out.

Feel free to discard my comment since the Dialer seems to be used also in another places and changing the signature can break some external users, and this will unnecessary complicate this, sorry 😅

staging/src/k8s.io/client-go/tools/portforward/portforward.go:160:func NewOnAddresses(dialer httpstream.Dialer, addresses []string, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error) {
test/e2e/storage/drivers/proxy/portproxy.go:197:func dial(ctx context.Context, prefix string, dialer httpstream.Dialer, port int) (s *stream, finalErr error) {

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jul 26, 2021
Signed-off-by: arkbriar <arkbriar@gmail.com>
Signed-off-by: arkbriar <arkbriar@gmail.com>
@arkbriar arkbriar force-pushed the support_cancelable_exec_stream branch from 8dd91cf to b7e6c23 Compare November 2, 2022 03:49
@arkbriar
Copy link
Contributor Author

arkbriar commented Nov 2, 2022

/retest-required

1 similar comment
@arkbriar
Copy link
Contributor Author

arkbriar commented Nov 2, 2022

/retest-required

@liggitt
Copy link
Member

liggitt commented Nov 2, 2022

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 2, 2022
@liggitt
Copy link
Member

liggitt commented Nov 2, 2022

thanks for all the iterations on this

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arkbriar, liggitt

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 2, 2022
@arkbriar
Copy link
Contributor Author

arkbriar commented Nov 2, 2022

/test pull-kubernetes-e2e-gce-ubuntu-containerd

@aojea
Copy link
Member

aojea commented Nov 2, 2022

/retest

failures are related to #113548

/lgtm

Thanks @arkbriar for persisting, sorry for the time it took 😄

@k8s-ci-robot k8s-ci-robot merged commit 3cf75a2 into kubernetes:master Nov 3, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 3, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Feb 7, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Feb 7, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Feb 7, 2023
gardener-prow bot pushed a commit to gardener/gardener that referenced this pull request Feb 7, 2023
* Replace `pointer.StringPtr` with `pointer.String`

* Replace `pointer.BoolPtr` with `pointer.Bool`

* Replace `pointer.Int32Ptr` with `pointer.Int32`

* Replace `pointer.Int64Ptr` with `pointer.Int64`

* Replace deprecated `sets.String` usages appropriately

* Replace `io/ioutil.ReadAll` with `io.ReadAll`

As of Go 1.16, this function simply calls `io.ReadAll`.

* Use `executor.StreamWithContext` instead of `executor.Stream`

kubernetes/kubernetes#103177

* Use dedicated schemes for tests
kkourt added a commit to cilium/tetragon that referenced this pull request Apr 4, 2023
golangci reported:
 tests/e2e/helpers/exec.go:49:9 staticcheck  SA1019: exec.Stream is
 deprecated: use StreamWithContext instead to avoid possible resource
 leaks. See kubernetes/kubernetes#103177 for
 details.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this pull request Apr 4, 2023
golangci reported:
 tests/e2e/helpers/exec.go:49:9 staticcheck  SA1019: exec.Stream is
 deprecated: use StreamWithContext instead to avoid possible resource
 leaks. See kubernetes/kubernetes#103177 for
 details.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this pull request Apr 5, 2023
golangci reported:
 tests/e2e/helpers/exec.go:49:9 staticcheck  SA1019: exec.Stream is
 deprecated: use StreamWithContext instead to avoid possible resource
 leaks. See kubernetes/kubernetes#103177 for
 details.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
andrerun pushed a commit to andrerun/gardener that referenced this pull request Jul 6, 2023
* Replace `pointer.StringPtr` with `pointer.String`

* Replace `pointer.BoolPtr` with `pointer.Bool`

* Replace `pointer.Int32Ptr` with `pointer.Int32`

* Replace `pointer.Int64Ptr` with `pointer.Int64`

* Replace deprecated `sets.String` usages appropriately

* Replace `io/ioutil.ReadAll` with `io.ReadAll`

As of Go 1.16, this function simply calls `io.ReadAll`.

* Use `executor.StreamWithContext` instead of `executor.Stream`

kubernetes/kubernetes#103177

* Use dedicated schemes for tests
@reckless-huang
Copy link

/复检

故障与 #113548 有关

/lgtm

感谢您的坚持,对不起,花了😄时间

greate job

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/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/kubectl area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Development

Successfully merging this pull request may close these issues.

How to cancel a RESTClient exec? Can add context to the request?