Conversation
…rflow when two reference eachother
brandonc
previously approved these changes
Feb 4, 2025
Collaborator
brandonc
left a comment
There was a problem hiding this comment.
Seems like a good idea to track the already-included models by id/type and avoid the recursion step if we already saw a particular record.
This was referenced Feb 5, 2025
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.
Description of Bug
This fix relates to a bug seen downstream in go-tfe. In short, when the provided data model has circular references within it's relations AND those relations are specified in "included" we can run into stack overflows. Specifically if two included items have included relations to each other. Such a situation leads to the unmarshal process getting stuck in a endless recursive loop.
For a data model like so:
When we specify the included as "project" and "organization", if within the included there is a project that is also the
DefaultProjectof an includedOrganizationwe see a call stack like so:As we forever try to render the included relationships.
The Fix
When unmarshalling a nodes relationships, if the relationship is given in the included, we store a pointer to the results of it's unmarshalling within the
includedNodestruct that is passed throughout the call stack. If this same item is in a relationship and included elsewhere, we opt to use the stored result to avoid the potential infinite loop we see above.Testing
Added a test, with associated data model edits, that captures this behavior. If you wish to see the stack overflow that is caused without the fix, you can simply comment out this code section:
And run
TestUnmarshalMany_relationships_with_circular_inclusionto see the stack overflow occur.