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

Return shallow copy of validator set in platformVM's validator manager #3512

Merged

Conversation

yacovm
Copy link
Contributor

@yacovm yacovm commented Nov 1, 2024

Why this should be merged

PlatformVM's manager returns validators as a map, and caches the same instance. Then, it might be that different goroutines try to access this map instance concurrently, which is not safe and causes a data race.

How this works

This commit simply shallow clones the map when returning it from within the validator manager.

How this was tested

CI

Need to be documented in RELEASES.md?

No

@StephenButtolph StephenButtolph added bug Something isn't working antithesis Related to an issue reported by Antithesis labels Nov 1, 2024
@StephenButtolph StephenButtolph added this to the v1.11.13 milestone Nov 1, 2024
@@ -230,7 +231,7 @@ func (m *manager) GetValidatorSet(
m.metrics.IncValidatorSetsCreated()
m.metrics.AddValidatorSetsDuration(duration)
m.metrics.AddValidatorSetsHeightDiff(currentHeight - targetHeight)
return validatorSet, nil
return maps.Clone(validatorSet), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the issue also comes from L203

Copy link
Contributor

@StephenButtolph StephenButtolph left a comment

Choose a reason for hiding this comment

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

Is it possible to add a regression test for this?

PlatformVM's manager returns validators as a map, and caches the same instance.
Then, it might be that different goroutines try to access this map instance concurrently, which is not safe.

This commit simply shallow clones the map when returning it from within the validator manager.

Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
@yacovm yacovm force-pushed the shallowCloneGetValidatorSet branch from 1fe07eb to cf74836 Compare November 1, 2024 19:32
@StephenButtolph StephenButtolph added this pull request to the merge queue Nov 3, 2024
Merged via the queue into ava-labs:master with commit 5798ac0 Nov 3, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
antithesis Related to an issue reported by Antithesis bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants