fix: prevent infinite loop in handle_metadata_vars when variable references cycle#196
Merged
patrickchugh merged 1 commit intoMay 20, 2026
Conversation
…a_vars The while loop in handle_metadata_vars only broke when value == old_value (a fixed point). When find_replace_values produces an oscillating sequence (e.g. local.A → local.B → local.A → ...), value changes each iteration but never resolves — causing an infinite hang. Add a _seen_values set to detect cycles. If the current value has already been visited in this resolution pass, emit the existing "unresolved references remain" warning and break immediately. Reproduced with a Cognito module that defines a local.lambda_arn map — its unresolvable references caused terravision to hang indefinitely after printing the "Processing resources" step, with no timeout or error output.
patrickchugh
approved these changes
May 20, 2026
Owner
|
@jespo2021 Grateful for the PR. Thanks! |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
handle_metadata_varshangs indefinitely whenfind_replace_valuesproduces a cycling sequence of values (e.g.local.A→local.B→local.A→ ...).The existing guard only breaks when
value == old_value(a fixed point). Cycles are different: the value changes each iteration and never repeats consecutively, so the break is never reached.Root cause
If
find_replace_valuesexpandslocal.Ato something containinglocal.B, thenlocal.Bback to something containinglocal.A, the loop runs forever with no output.Fix
Add a
_seen_valuesset that tracks every value encountered in the current resolution pass. If the same value appears again, we've detected a cycle — emit the existing "unresolved references remain" warning and break.How I found it
Running
terravision drawagainst a Terraform project that uses a Cognito module with alocal.lambda_arnmap. The module defines optional lambda ARN locals that are conditionally populated — when the lambda isn't configured, the reference chain cycles instead of resolving to a terminal value. Terravision printed all the "Processing resources" entries, then hung silently forever with 100% CPU.Tested
Confirmed fix resolves the hang on the reproducing project. The diagram generates successfully after the patch.