Merged
Conversation
7ea8fac to
cb800bb
Compare
Instances of the same AbsResource may share the same Dependencies, which could point to the same backing array of values. Since address values are not pointers, and not meant to be shared, we must copy the value before sorting the slice in-place. Because individual instances of the same resource may be encoded to state concurrently, failure to copy the slice first can result in a data race.
This runs relatively quickly, and there is at least 1 test with concurrent operations.
cb800bb to
2bd7291
Compare
alisdair
approved these changes
Apr 28, 2022
Contributor
|
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
This was referenced Apr 28, 2022
Contributor
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instances of the same
AbsResourcemay share the sameDependencies, which could point to the same backing array of values. Since address values are not pointers, and not meant to be shared, we must copy the value before sorting the slice in-place. This follows the documentation forResourceInstanceObjectwhich states that it must not be mutated once it has been created. Because individual instances of the same resource may be encoded to state concurrently, failure to copy the slice first can result in a data race.Dependencies in core are handled at the resource level, so when evaluating the plan, we start with a single node for a resource with the dependencies already attached. As that resource is expanded, first from a
nodeExpandPlannableResourceto aPlannableResourefor each module instance, then finally to a number ofPlannableResourceInstance, the list of dependencies is copied into each subsequent data structure, and finally to the instance state. This list is intended to be used as a value, like the addresses it contains, and should be read-only, but that invariant was broken by the sorting which happened during instance state encoding.Update the encoding test to trigger the race, and add the states package to the race-detector tests.
Fixes #30894
Fixes #30935