fix panic when evaluating cyclic environment references #466
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.
We track the lifetime of each environments import evaluations to detect cyclic imports. Right now this is tracked while we're evaluating the imports decl.
However, #443 introduced a way to import environment values inline. Once we've started evaluating the environment values root, we currently stop tracking whether the environment is evaluating because we're done with all the imports.
The result of this is that a cyclic environment reference will look up the environment name in the imports map and won't detect that it is still evaluating. Since the cached value in the imports map hasn't been set yet (since the environment hasn't finished evaluating) we return nil as the value. This results in a panic when we try to actually access the value.
To fix this, I'm just hoisting the evaluation lifetime tracking to the evaluation root, rather than just the imports node, so it'll correctly detect cycles for inline references.
Fixes https://github.com/pulumi/pulumi-service/issues/26277