go-zero
go-zero copied to clipboard
fix(conf): Memory leak on loading YAML with cyclic dependencies
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:
type Node struct {
Name string `json:"name"`
Children []*Node `json:"children,optional"`
}
Solution:
The fix introduces a robust cycle detection mechanism within the buildFieldsInfo function. It now uses a visited map to keep track of processed types.
I also add a test to show whether it works
close #5140
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? Let us know!