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 map iteration and map write #727

Merged
merged 2 commits into from
Jul 12, 2023

Conversation

luckymrwang
Copy link
Contributor

@luckymrwang luckymrwang commented Jul 7, 2023

Provide a description of what has been changed

Checklist

Fixes #726

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! ❤️
Could you update changelog as well?

Comment on lines +88 to +90
for key, val := range r.countMap {
cts.Counts[key] = val
}
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we just moving the concurrency conflicts just to here? Should we use a mutex to protect this code? @t0rr3sp3dr0 WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be fine. The problem is that we were passing the reference of the internal Queue map, that is protected by a mutex, to the Counts struct, that is not aware of the mutex. So when someone interacted with the Counts struct, the internal Queue map was being used without locking the mutex. Now the map is being copied to the Counts struct, fixing the problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Counts struct is not thread-safe and its instances are not being accessed by multiple routines, so we don’t need a mutex that side.

Copy link
Contributor

@t0rr3sp3dr0 t0rr3sp3dr0 left a comment

Choose a reason for hiding this comment

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

@luckymrwang, to prevent regressions in the future, can you implement a test to make sure the Current method always returns a copy of the internal map and not a reference to it? Given we are now returning a new map, it’s a good idea to also test if the Counts map contains the same values as the Queue map.

@luckymrwang
Copy link
Contributor Author

@luckymrwang, to prevent regressions in the future, can you implement a test to make sure the Current method always returns a copy of the internal map and not a reference to it? Given we are now returning a new map, it’s a good idea to also test if the Counts map contains the same values as the Queue map.

@t0rr3sp3dr0 Ok, I will add it later.

@JorTurFer
Copy link
Member

Hi @luckymrwang ,
We plan to cut a hotfix release soon (this week). Do you think that you will have enough time?

@luckymrwang
Copy link
Contributor Author

luckymrwang commented Jul 12, 2023

Hi @luckymrwang , We plan to cut a hotfix release soon (this week). Do you think that you will have enough time?

@JorTurFer @t0rr3sp3dr0 I was busy the past two days and the latest code has been committed.

@JorTurFer
Copy link
Member

JorTurFer commented Jul 12, 2023

Statics checks are faillig, could you review them and update changelog as well?

@luckymrwang
Copy link
Contributor Author

Statics checks are faillig, could you review them and update changelog as well?

@JorTurFer The latest code has been committed.

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

Please, add a note in the changelog about this PR: https://github.com/kedacore/http-add-on/blob/main/CHANGELOG.md#fixes


err = memory.Resize("host1", 1)
r.NoError(err)
memory.Resize("host2", 1)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
memory.Resize("host2", 1)
err = memory.Resize("host2", 1)

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the fix ❤️
PTAL @t0rr3sp3dr0

@t0rr3sp3dr0
Copy link
Contributor

lgtm

@JorTurFer JorTurFer merged commit ecd4a41 into kedacore:main Jul 12, 2023
18 checks passed
JorTurFer pushed a commit to JorTurFer/http-add-on that referenced this pull request Jul 28, 2023
@luckymrwang luckymrwang deleted the fix-bug branch September 13, 2023 01:40
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.

fatal error: concurrent map iteration and map write
3 participants