Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DengY11 wants to merge 2 commits into zeromicro:master
base: master
Choose a base branch
Loading
from DengY11:fix/config-memory-leak

Conversation

Copy link
Contributor

@DengY11 DengY11 commented Sep 23, 2025
edited
Loading

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 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

Reviewers

Copilot code review Copilot Copilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Memory leak occurred,When loading the yaml configuration file

1 participant

AltStyle によって変換されたページ (->オリジナル) /