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 addAnnotationWithClusterName crash #3966

Merged
merged 1 commit into from
Aug 22, 2023

Conversation

ikaven1024
Copy link
Member

@ikaven1024 ikaven1024 commented Aug 21, 2023

What type of PR is this?
/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #3960

Special notes for your reviewer:

When listing from an Infromer, it returns reference of objects in cache.

func (c *threadSafeMap) List() []interface{} {
c.lock.RLock()
defer c.lock.RUnlock()
list := make([]interface{}, 0, len(c.items))
for _, item := range c.items {
list = append(list, item)
}
return list
}

When two or more search requests come at the same time, and all requests list objects from informer and add cluster annotation into the same objecs, it raises crash.

items = append(items, addAnnotationWithClusterName(cloneObjects, cluster.Name)...)

Does this PR introduce a user-facing change?:

`karmada-search`: Fixed a panic due to concurrent mutating objects in the informer cache.

Signed-off-by: yingjinhui <yingjinhui@didiglobal.com>
@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 21, 2023
@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 21, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #3966 (5763248) into master (48a37ab) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #3966      +/-   ##
==========================================
- Coverage   54.81%   54.78%   -0.04%     
==========================================
  Files         232      232              
  Lines       22521    22525       +4     
==========================================
- Hits        12345    12340       -5     
- Misses       9499     9508       +9     
  Partials      677      677              
Flag Coverage Δ
unittests 54.78% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
pkg/registry/search/storage/cache.go 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/assign

@ikaven1024 Thank you so much for the quick response and hard work!

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 22, 2023
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2023
@karmada-bot karmada-bot merged commit cb4a8b3 into karmada-io:master Aug 22, 2023
@ikaven1024 ikaven1024 deleted the fix-map-crash branch August 22, 2023 02:34
@RainbowMango
Copy link
Member

Just opened #3968 to track the backport tasks.

karmada-bot added a commit that referenced this pull request Aug 23, 2023
…66-upstream-release-1.4

Automated cherry pick of #3966: fix addAnnotationWithClusterName crash
karmada-bot added a commit that referenced this pull request Aug 23, 2023
…66-upstream-release-1.5

Automated cherry pick of #3966: fix addAnnotationWithClusterName crash
karmada-bot added a commit that referenced this pull request Aug 23, 2023
…66-upstream-release-1.6

Automated cherry pick of #3966: fix addAnnotationWithClusterName crash
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

karmada-search may crash due to concurrent map read and map write
4 participants