Error on cyclic YAML anchor references instead of stack overflow#5500
Open
simonfaltum wants to merge 2 commits into
Open
Error on cyclic YAML anchor references instead of stack overflow#5500simonfaltum wants to merge 2 commits into
simonfaltum wants to merge 2 commits into
Conversation
Co-authored-by: Isaac
Contributor
Waiting for approvalBased on git history, these people are best suited to review:
Eligible reviewers: Suggestions based on git history. See OWNERS for ownership rules. |
Collaborator
|
Commit: ff32c31
24 interesting tests: 15 SKIP, 7 KNOWN, 2 flaky
Top 28 slowest tests (at least 2 minutes):
|
Drop per-test-case explanation comments from yaml_anchor_test.go and trim the loadAlias comment to the why only. No behavior changes. Co-authored-by: Isaac
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.
Why
Found during a full-repo review of the CLI. A self-referential YAML anchor such as
a: &x {child: *x}indatabricks.ymlcrashes any command that loads the config (for examplebundle validate) with an uncatchablefatal error: stack overflow. The yaml.v3 node graph is cyclic in this case and the loader walked it with no cycle detection.Changes
Before, expanding a cyclic alias recursed until the process died; now the loader returns a regular error pointing at the offending alias, e.g.
yaml (databricks.yml:2:10): cyclic reference to anchor "x".The loader in
libs/dyn/yamlloader/loader.gonow tracks the set of alias nodes currently being expanded. Revisiting an alias that is still on the expansion stack means the anchor contains itself, soloadAliaserrors out. The alias is removed from the set once its expansion completes, because reaching the same alias node again on a different path (through another alias to an enclosing anchor) is valid YAML, not a cycle. This mirrors how the yaml.v3 decoder guards its own alias expansion.Test plan
TestYAMLAnchor09: a self-referential anchor returns the cyclic-reference error. Confirmed it crashes withfatal error: stack overflowbefore the fix and passes after.TestYAMLAnchor10: re-expanding the same alias node on separate paths (an anchor containing an alias, referenced twice) still loads correctly.go test ./libs/dyn/...passes.This pull request and its description were written by Isaac.