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 datarace when reading handlers in SharedHandler #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexandreLamarre
Copy link

No description provided.

@alexandreLamarre alexandreLamarre marked this pull request as ready for review July 31, 2024 19:19
@alexandreLamarre alexandreLamarre requested a review from a team as a code owner July 31, 2024 19:19
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

This seems to be close to what the code was previously doing: a3ff816. I think we need more consideration on this one before making changes.

Signed-off-by: Alexandre Lamarre <alexandre.lamarre@suse.com>
@ericpromislow
Copy link
Contributor

Before the code was holding the lock while it ran each handler (and there are various metrics in the loop that suggest people have been concerned with how long it takes to update an object by applying an array of (mutating webhook?) handlers to it. Now the use of the lock suggests that it's waiting for the array of handlers to be built, and then it uses it.

But the fact of the race condition in the helm-lock tests suggest that something else is modifying the array while the lasso sharedhandler loops through it, so it's safer to make a shallow copy of it and loop through that. If the underlying
array changes while the OnChange method loops through, the only loss is that our mutation might be out-dated.

Copy link
Contributor

@ericpromislow ericpromislow left a comment

Choose a reason for hiding this comment

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

Well, I wrote this code, but I think it's correct, and not onerously expensive.

@tomleb
Copy link
Contributor

tomleb commented Aug 8, 2024

We could avoid making a copy for every OnChange calls by creating a new handler slice when a new handler is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants