Skip to content

Conversation

@ffromani
Copy link
Contributor

@ffromani ffromani commented Nov 7, 2024

What type of PR is this?

/kind bug
/kind failing-test
/kind regression

What this PR does / why we need it:

Since the GA graduation of memory manager in #128517 we are sharing the initial container map across managers.

The intention of this sharing was not to actually share a data structure, but

  1. save the relatively expensive relisting from runtime
  2. have all the managers share a consistent view - even though the chance for misalignement tend to be tiny.

The unwanted side effect though is now all the managers race to modify a shared, not thread safe data structure.

The fix is to clone (deepcopy) the computed map when passing it to each manager. This restores the old semantic of the code.

This issue brings the topic of possibly managers go out of sync since each of them maintain a private view of the world. This risk is real, yet very much likely tiny, and this is how the code worked for most of the lifetime, so the plan is to look at this and evaluate possible improvements later on.

Which issue(s) this PR fixes:

Fixes #128638

Special notes for your reviewer:

N/A

Does this PR introduce a user-facing change?

NONE

@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/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/regression Categorizes issue or PR as related to a regression from a prior release. 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. labels Nov 7, 2024
@k8s-ci-robot k8s-ci-robot added area/kubelet 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 Nov 7, 2024
@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

/test pull-crio-cgroupv1-node-e2e-resource-managers
/test pull-kubernetes-node-e2e-containerd-serial-ec2
/test pull-kubernetes-node-kubelet-serial-containerd
/test pull-kubernetes-node-kubelet-serial-cpu-manager
/test pull-kubernetes-node-kubelet-serial-memory-manager
/test pull-kubernetes-node-kubelet-serial-topology-manager
/test pull-kubernetes-node-kubelet-serial-containerd

@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

/cc @SergeyKanzhelev

@haircommander
Copy link
Contributor

/lgtm

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

LGTM label has been added.

Git tree hash: 8228c9743572fdfa082c8ca60f8edf45a9f95c48

Since the GA graduation of memory manager in kubernetes#128517
we are sharing the initial container map across managers.

The intention of this sharing was not to actually share a data
structure, but
1. save the relatively expensive relisting from runtime
2. have all the managers share a consistent view - even though the
   chance for misalignement tend to be tiny.

The unwanted side effect though is now all the managers race
to modify a data shared, not thread safe data structure.

The fix is to clone (deepcopy) the computed map when passing it
to each manager. This restores the old semantic of the code.

This issue brings the topic of possibly managers go out of sync
since each of them maintain a private view of the world.
This risk is real, yet this is how the code worked for
most of the lifetime, so the plan is to look at this and evaluate
possible improvements later on.

Signed-off-by: Francesco Romani <[email protected]>
@ffromani ffromani force-pushed the unshare-containermap-among-managers branch from 4b6bfae to 2a99bfc Compare November 7, 2024 15:03
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Nov 7, 2024
@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

New changes are detected. LGTM label has been removed.

wanted to add another test to exercise the new workhorse Clone function

@haircommander
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 5a434c477fb4d8dac0226d0e5266de301a06845b

@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

/test pull-crio-cgroupv1-node-e2e-resource-managers
/test pull-kubernetes-node-e2e-containerd-serial-ec2
/test pull-kubernetes-node-kubelet-serial-containerd
/test pull-kubernetes-node-kubelet-serial-cpu-manager
/test pull-kubernetes-node-kubelet-serial-memory-manager
/test pull-kubernetes-node-kubelet-serial-topology-manager
/test pull-kubernetes-node-kubelet-serial-containerd

@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

/assign @klueska
/assign @mrunalp

@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

/triage accepted
/priority critical-urgent

again pretty evident from the context

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. and removed 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. labels Nov 7, 2024
@dims
Copy link
Member

dims commented Nov 7, 2024

The addition of the Clone method and its use is very straight forward, so i am comfortable landing this to unblock ourselves from test failures so other things can land just before code freeze.

/approve
/lgtm

@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 7, 2024
@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

/test pull-kubernetes-integration

failure seems to be unrelated

@SergeyKanzhelev
Copy link
Member

@ffromani why any of those managers are writing to this map?

@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

@ffromani why any of those managers are writing to this map?

because the reconciliation loops, and to keep their copy up to date when container come and go

@SergeyKanzhelev
Copy link
Member

@ffromani why any of those managers are writing to this map?

because the reconciliation loops, and to keep their copy up to date when container come and go

oh, I see. This is just an initial list. I'm surprised this is the first time we see it panics

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, ffromani, SergeyKanzhelev

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 merged commit 847be85 into kubernetes:master Nov 7, 2024
21 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.32 milestone Nov 7, 2024
@ffromani ffromani deleted the unshare-containermap-among-managers branch November 7, 2024 19:47
@ffromani
Copy link
Contributor Author

ffromani commented Nov 7, 2024

@ffromani why any of those managers are writing to this map?

because the reconciliation loops, and to keep their copy up to date when container come and go

oh, I see. This is just an initial list. I'm surprised this is the first time we see it panics

previously, each manager used its instance of the map returned by buildContainerMapAndRunningSetFromRuntime. The main(/only) reason was each manager could in theory be enabled independently. Device manager happened to not use the map, so the race was present but dormant.

When we GA'd memory manager we removed the feature gate and the duplicated call to buildContainerMapAndRunningSetFromRuntime (doesn't make sense to call it twice in 30 lines of code) and triggered the bug. The commit message provides more context.

ffromani added a commit to ffromani/kubernetes that referenced this pull request Nov 7, 2024
ffromani added a commit to ffromani/kubernetes that referenced this pull request Jan 8, 2025
ffromani added a commit to ffromani/kubernetes that referenced this pull request Jan 30, 2025
richabanker pushed a commit to richabanker/kubernetes that referenced this pull request Feb 28, 2025
zylxjtu pushed a commit to zylxjtu/kubernetes that referenced this pull request Mar 20, 2025
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. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. 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. 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.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

kubelet crash: fatal error: concurrent map writes

8 participants