Skip to content

Conversation

DengY11
Copy link
Contributor

@DengY11 DengY11 commented Sep 23, 2025

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

Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kevwan kevwan requested a review from Copilot September 27, 2025 03:51
@kevwan kevwan force-pushed the fix/config-memory-leak branch from bfc5a41 to 0f63f2d Compare September 27, 2025 03:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak occurred,When loading the yaml configuration file

1 participant