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 goroutine leaks in TestConfigurationChannels #107163

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

cyclinder
Copy link
Contributor

Signed-off-by: cyclinder qifeng.guo@daocloud.io

What type of PR is this?

/kind bug

What this PR does / why we need it:

fix goroutine leaks in TestConfigurationChannels.

func TestConfigurationChannels(t *testing.T) {
mux := NewMux(nil)
channelOne := mux.Channel("one")
if channelOne != mux.Channel("one") {
t.Error("Didn't get the same muxuration channel back with the same name")
}
channelTwo := mux.Channel("two")
if channelOne == channelTwo {
t.Error("Got back the same muxuration channel for different names")
}
}

Which issue(s) this PR fixes:

Fixes #107089

Special notes for your reviewer:

We should consider whether it is appropriate to use wait.NeverStop here:

go wait.Until(func() { m.listen(source, newChannel) }, 0, wait.NeverStop)

Does this PR introduce a user-facing change?

NONE

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


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. 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. 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. labels Dec 21, 2021
@k8s-ci-robot
Copy link
Contributor

@cyclinder: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Dec 21, 2021
@cyclinder
Copy link
Contributor Author

cyclinder commented Dec 21, 2021

/sig testing
/sig node

@k8s-ci-robot k8s-ci-robot added sig/testing Categorizes an issue or PR as relevant to SIG Testing. sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 21, 2021
@cyclinder
Copy link
Contributor Author

/test pull-kubernetes-integration

stopCh = stopChes[0]
} else {
stopCh = wait.NeverStop
}
Copy link
Member

Choose a reason for hiding this comment

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

Rather than doing this for backwards compatibility, I wonder if it'd be cleaner to add a new method to the type. E.g. ChannelWithContext(ctx context.Context, source string) chan interface{}.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, this is not in library code (not in staging) so might just break the signature and update the callers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @ash2k, if we add a new method there, do we need to look at all callers? If so, I would like the PR to add the new method and update TestConfigurationChannels . Then create a new PR to update all the callers. and decide whether they should call the new method or the old.

Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need yet another method, we can just change this one. The caller should always be responsible for stopping the goroutines they start, so a method without a way to stop them is a bad API. Hence, in my opinion, we should change this one rather just than adding a new one (change bad API to good API).

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 found a lot of code in the kubelet that uses wait.NeverStop, which doesn't seem to care about stopping the goroutine. If we change this method to ChannelWithContext(ctx context.Context, source string) chan interface, we need to cancel this ctx somewhere uniformly, but I can't find the right place

Copy link
Member

Choose a reason for hiding this comment

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

It's fine, we don't need to fix the world in this PR :)

@cyclinder cyclinder force-pushed the fix_leak_goroutine branch 2 times, most recently from 31d2e39 to f871c1e Compare January 4, 2022 13:36
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/kubelet and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 4, 2022
@cyclinder
Copy link
Contributor Author

/cc @dims @dchen1107

@k8s-ci-robot k8s-ci-robot requested review from dchen1107 and dims January 7, 2022 10:26
@dims
Copy link
Member

dims commented Jan 7, 2022

/assign @ash2k

@ash2k please assign it back to me after you are happy with this

pkg/kubelet/config/config_test.go Outdated Show resolved Hide resolved
pkg/util/config/config.go Outdated Show resolved Hide resolved
@cyclinder
Copy link
Contributor Author

/test pull-kubernetes-unit pull-kubernetes-e2e-kind

@cyclinder
Copy link
Contributor Author

/cc @ash2k

@k8s-ci-robot k8s-ci-robot requested a review from ash2k January 10, 2022 08:37
Copy link
Member

@ash2k ash2k left a comment

Choose a reason for hiding this comment

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

/lgtm
/assign @dims

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2022
pkg/kubelet/kubelet.go Outdated Show resolved Hide resolved
Signed-off-by: cyclinder <qifeng.guo@daocloud.io>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2022
@cyclinder
Copy link
Contributor Author

/test pull-kubernetes-unit

@dims
Copy link
Member

dims commented Jan 10, 2022

thanks @cyclinder and @ash2k. the unit test failure seems unrelated, right?

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ash2k, cyclinder, dims

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 Jan 10, 2022
@cyclinder
Copy link
Contributor Author

thanks @cyclinder and @ash2k. the unit test failure seems unrelated, right?

/approve

yeah, retest was successful

@ash2k
Copy link
Member

ash2k commented Jan 10, 2022

/lgtm

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2022
@k8s-ci-robot k8s-ci-robot merged commit a0dfd95 into kubernetes:master Jan 11, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Jan 11, 2022
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/kubelet 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. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. 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.
Projects
Development

Successfully merging this pull request may close these issues.

goroutine leaks in TestConfigurationChannels
4 participants