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: replace RunContext and ProjectContext contextValues with concurrency safe ContextValues #2544

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

hugorut
Copy link
Contributor

@hugorut hugorut commented Jul 5, 2023

This change introduces the ContextValues struct to both RunContext and ProjectContext, replacing the previously used map[string]interface{}. This change was introduced to enhance thread safety in our codebase by preventing concurrent read/write operations to these shared resources, which could lead to unpredictable behavior or data races.

Prior to this change the ContextValues() could hit a conccurent write panic because it was returning the actual map and not a copy of it, so when we read from the map it could potentially be written to in a separate goroutine.

To fix this Values now returns a copy of the underlying map. I've also introduced a GetValue method to safely read values.

…oncurrency safe `ContextValues`

This change introduces the ContextValues struct to both RunContext and ProjectContext, replacing the previously used map[string]interface{}. This change is introduced to enhance thread safety in our codebase by preventing concurrent read/write operations to these shared resources, which could lead to unpredictable behavior or data races.

Prior to this change the `ContextValues()` could hit a conccurent write panic because it was returning the actual map and not a copy of it, so when we read from the map it could potentially be written to in a separate goroutine.

To fix this `Values` now returns a copy of the underlying map, and I've introduced a `GetValue` method to safely read values.
@hugorut hugorut self-assigned this Jul 5, 2023
@hugorut hugorut marked this pull request as ready for review July 5, 2023 09:40
@hugorut hugorut requested a review from aliscott July 5, 2023 10:02
Copy link
Member

@aliscott aliscott left a comment

Choose a reason for hiding this comment

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

Thanks!

@hugorut hugorut merged commit 48d8ba5 into master Jul 6, 2023
9 checks passed
@hugorut hugorut deleted the fix/context-values-map branch July 6, 2023 13:05
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.

None yet

2 participants