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

make podTopologyHints protected by lock #95111

Merged
merged 1 commit into from Jan 26, 2021
Merged

Conversation

choury
Copy link
Contributor

@choury choury commented Sep 28, 2020

What type of PR is this?
/kind bug

What this PR does / why we need it:

It crashed kubelet by
"concurrent map read and map write"

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Resolve a "concurrent map read and map write" crashing error in the kubelet

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. size/XS Denotes a PR that changes 0-9 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 Sep 28, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @choury. 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/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 28, 2020
@nolancon
Copy link

/ok-to-test
/test pull-kubernetes-node-kubelet-serial-topology-manager

@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 Sep 28, 2020
@choury
Copy link
Contributor Author

choury commented Sep 28, 2020

/test pull-kubernetes-node-kubelet-serial-topology-manager

@choury
Copy link
Contributor Author

choury commented Sep 30, 2020

/retest

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 29, 2020
@ehashman ehashman added this to Needs Reviewer in SIG Node PR Triage Jan 6, 2021
@ehashman ehashman moved this from Needs Reviewer to In Progress in SIG Node PR Triage Jan 6, 2021
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 14, 2021
@choury
Copy link
Contributor Author

choury commented Jan 14, 2021

/retest

@choury
Copy link
Contributor Author

choury commented Jan 14, 2021

/test pull-kubernetes-e2e-gce-ubuntu-containerd
/test pull-kubernetes-node-kubelet-serial-topology-manager

@choury
Copy link
Contributor Author

choury commented Jan 14, 2021

/remove-lifecycle stale

@choury choury requested a review from klueska January 20, 2021 05:34
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change is unnecessary.

Copy link
Contributor Author

@choury choury Jan 21, 2021

Choose a reason for hiding this comment

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

It was modified by goimport like many other commit as here or there .

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand, but that still doesn't mean it should be part of this PR.
If I had been the reviewer on those PRs I would have asked them to remove that change.

Comment on lines 71 to 86
func (s *scope) Lock() {
s.mutex.Lock()
}

func (s *scope) Unlock() {
s.mutex.Unlock()
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe what I mentioned before wasn't clear.

I wasn't opposed to having a getter/setter around s.podTopologyHints that applies a lock before accessing it. I just didn't want that to be part of the outward facing Scope interface. It's fine to put it on the underlying concrete scope type though.

As such, I think a better abstraction here would be:

func (s *scope) getTopologyHints(podUID string, containerName string) TopologyHint {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return s. podTopologyHints[podUID][containerName]
}

func (s *scope) setTopologyHints(podUID string, containerName string, th TopologyHint) {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	if s. podTopologyHints[podUID)] == nil {
		s. podTopologyHints[podUID)] = make(map[string]TopologyHint)
	}
	s. podTopologyHints[podUID][containerName] = th
}

Comment on lines 79 to 89
func (s *scope) GetAffinity(podUID string, containerName string) TopologyHint {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.podTopologyHints[podUID][containerName]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Following my advice above, this would then become:

func (s *scope) GetAffinity(podUID string, containerName string) TopologyHint {
	return s.getTopologyHints(podUID, containerName)
}

pkg/kubelet/cm/topologymanager/scope.go Outdated Show resolved Hide resolved
pkg/kubelet/cm/topologymanager/scope_container.go Outdated Show resolved Hide resolved
Comment on lines 58 to 60
s.Lock()
if (s.podTopologyHints)[string(pod.UID)] == nil {
(s.podTopologyHints)[string(pod.UID)] = make(map[string]TopologyHint)
}

klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
(s.podTopologyHints)[string(pod.UID)][container.Name] = bestHint
s.Unlock()

Copy link
Contributor

Choose a reason for hiding this comment

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

And this would become:

klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
s.setTopologyHints(string(pod.UID), container.Name, bestHint)

Comment on lines 58 to 66
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)

s.Lock()
if (s.podTopologyHints)[string(pod.UID)] == nil {
(s.podTopologyHints)[string(pod.UID)] = make(map[string]TopologyHint)
}

(s.podTopologyHints)[string(pod.UID)][container.Name] = bestHint
s.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

And this would become:

klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
s.setTopologyHints(string(pod.UID), container.Name, bestHint)

@klueska
Copy link
Contributor

klueska commented Jan 25, 2021

Hi @choury. I'm happy to approve this / merge this once the requested changes are made. Thanks.

It crashed kubelet by "concurrent map read and map write"
@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 Jan 26, 2021
@klueska
Copy link
Contributor

klueska commented Jan 26, 2021

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

@klueska
Copy link
Contributor

klueska commented Jan 26, 2021

/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 Jan 26, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: choury, klueska

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 26, 2021
@klueska
Copy link
Contributor

klueska commented Jan 26, 2021

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 26, 2021
@klueska
Copy link
Contributor

klueska commented Jan 26, 2021

@choury

This should probably be cherry-picked back to 1.20 as well:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-release/cherry-picks.md

Happy to lgtm/approve it once its created.

@choury
Copy link
Contributor Author

choury commented Jan 26, 2021

@klueska I will cherry pick it soon after merged.

@k8s-ci-robot k8s-ci-robot merged commit 889cf71 into kubernetes:master Jan 26, 2021
SIG Node PR Triage automation moved this from Waiting on Author to Done Jan 26, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Jan 26, 2021
@choury choury deleted the patch-2 branch January 26, 2021 12:23
choury added a commit to choury/kubernetes that referenced this pull request Jan 28, 2021
choury added a commit to choury/kubernetes that referenced this pull request Jan 28, 2021
k8s-ci-robot added a commit that referenced this pull request Feb 12, 2021
[release-1.19] cherry-pick of #95111: make podTopologyHints protected by lock
k8s-ci-robot added a commit that referenced this pull request Feb 12, 2021
…-upstream-release-1.20

[release-1.20] Automated cherry pick of #95111: make podTopologyHints protected by lock
k8s-ci-robot added a commit that referenced this pull request Feb 12, 2021
[release-1.18] cherry-pick of #95111: make podTopologyHints protected by lock
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. 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/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants