fix(conf): Memory leak on loading YAML with cyclic dependencies#5189
Open
DengY11 wants to merge 2 commits intozeromicro:masterfrom
Open
fix(conf): Memory leak on loading YAML with cyclic dependencies#5189DengY11 wants to merge 2 commits intozeromicro:masterfrom
DengY11 wants to merge 2 commits intozeromicro:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
bfc5a41 to
0f63f2d
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
Fixes a memory leak and stack overflow issue when loading YAML configurations with cyclic struct references. The problem occurred when structs contained self-referencing fields (like a Node with Children of type []*Node), causing infinite recursion during type analysis.
- Introduces cycle detection mechanism using a visited map to track processed types
- Refactors buildFieldsInfo function to accept and utilize the visited map parameter
- Consolidates buildStructFieldsInfo functionality directly into buildFieldsInfo
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/conf/config.go | Implements cycle detection by adding visited map parameter to buildFieldsInfo and related functions, removes buildStructFieldsInfo |
| core/conf/config_test.go | Updates test call to include new visited map parameter and adds comprehensive test for cyclic reference handling |
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.
I fixes a memory leak issue that occurred when loading a YAML configuration file with self-referencing structs. The previous implementation entered an infinite loop during type analysis, causing a stack overflow.
eg:
Solution:
The fix introduces a robust cycle detection mechanism within the
buildFieldsInfofunction. It now uses avisitedmap to keep track of processed types.I also add a test to show whether it works
close #5140