go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

fix(conf): Memory leak on loading YAML with cyclic dependencies

Open DengY11 opened this issue 3 months ago • 1 comments

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

DengY11 avatar Sep 23 '25 13:09 DengY11

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Sep 23 '25 13:09 codecov[bot]