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 concurrent usage issue of the same scheme #107876

Merged

Conversation

jlsong01
Copy link
Contributor

@jlsong01 jlsong01 commented Jan 31, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

Because of this scheme mutation, this leads to concurrent use of the same scheme to cause the program to panic. It would be ideal to do this in some concurrent safe manner.

Which issue(s) this PR fixes:

Fixes #107823, #107874

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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

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/S Denotes a PR that changes 10-29 lines, ignoring generated files. 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 31, 2022
@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 Jan 31, 2022
@k8s-ci-robot k8s-ci-robot added the sig/apps Categorizes an issue or PR as relevant to SIG Apps. label Jan 31, 2022
@jlsong01
Copy link
Contributor Author

/retest

1 similar comment
@jlsong01
Copy link
Contributor Author

/retest

Comment on lines 66 to 67
var mu = sync.Mutex{}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it'd be better to add a mutex as a member of the Scheme struct and use that internally in AddKnownTypeWithName when needed 🤔
I feel like that'd be cleaner than introducing a global lock and passing it to the constructor and initializing it as part of init. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it'd be better to add a mutex as a member of the Scheme struct and use that internally in AddKnownTypeWithName when needed

That approach sounds good

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it'd be better to add a mutex as a member of the Scheme struct and use that internally in AddKnownTypeWithName when needed

That approach sounds good

Actually, I'm now remembering what past me was thinking here. Because the scheme is used for multi-threaded reads, it would take a fair amount of work to wrap everything. If the tests were updated instead to have a newTestScheme function that returned a unique scheme for each test (the tests probably didn't intended to mutate a global scheme anyway), that will fix the issue without the fanout.

Copy link
Contributor Author

@jlsong01 jlsong01 Feb 2, 2022

Choose a reason for hiding this comment

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

Thanks Madhav and David.

Function NewTestScheme has been added to return a unique scheme for each test. PTAL

@fedebongio
Copy link
Contributor

/assign @MadhavJivrajani
(thank you for taking a look, your comment looks correct (thanks David!) )
/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 Feb 1, 2022
@jlsong01 jlsong01 changed the title add mutex lock for concurrent use of the same scheme Fix concurrent usage issue of the same scheme Feb 2, 2022
@deads2k
Copy link
Contributor

deads2k commented Feb 2, 2022

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 2, 2022
Copy link
Contributor

@MadhavJivrajani MadhavJivrajani left a comment

Choose a reason for hiding this comment

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

Thanks @jlsong01!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, jlsong01, MadhavJivrajani

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 cf9b5ab into kubernetes:master Feb 2, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 2, 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. 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. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

metadata fake: mutation of Scheme leads to concurrent map usage
5 participants