Skip to content

fix: tsdbCache and bse memleak.#34728

Merged
guanshengliang merged 1 commit intomainfrom
fix/main/mem-leak
Mar 10, 2026
Merged

fix: tsdbCache and bse memleak.#34728
guanshengliang merged 1 commit intomainfrom
fix/main/mem-leak

Conversation

@xiao-77
Copy link
Contributor

@xiao-77 xiao-77 commented Mar 10, 2026

Description

Issue(s)

https://project.feishu.cn/taosdata_td/defect/detail/6854367892

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings March 10, 2026 01:50
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the stability and resource management of the system by addressing two critical memory leaks. The changes ensure that allocated resources, specifically LRU caches and BSE components, are correctly deallocated during error conditions or object closure, preventing gradual memory consumption and improving overall system robustness.

Highlights

  • Memory Leak Fix in tsdbCache: Addressed a memory leak in tsdbOpenCache by ensuring that the pCache is properly cleaned up using taosLRUCacheCleanup if an error occurs during the cache opening process. Additionally, the pTsdb->lruCache assignment was moved to the success path.
  • Memory Leak Fix in vnodeOpen: Resolved a memory leak in vnodeOpen by explicitly calling bseClose(pVnode->pBse) and setting pVnode->pBse = NULL during the vnode cleanup process, ensuring proper resource deallocation for the BSE component.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • source/dnode/vnode/src/tsdb/tsdbCache.c
    • Ensured pTsdb->lruCache is assigned to pCache only upon successful cache initialization.
    • Implemented taosLRUCacheCleanup(pCache) in the error handling path of tsdbOpenCache to prevent memory leaks if cache initialization fails.
  • source/dnode/vnode/src/vnd/vnodeOpen.c
    • Added explicit bseClose(pVnode->pBse) call within the vnodeOpen cleanup logic to properly deallocate BSE resources.
    • Set pVnode->pBse to NULL after closing to prevent dangling pointers and ensure clean state.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

This PR addresses memory/resource leaks during vnode/TSDB initialization failure paths, ensuring allocated cache and blob-store engine resources are properly released when open steps fail.

Changes:

  • Close and nullify pVnode->pBse in vnodeOpen() error cleanup to avoid leaking the blob store engine handle.
  • Ensure tsdbOpenCache() cleans up the newly created LRU cache (taosLRUCacheCleanup) when a subsequent open step fails.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
source/dnode/vnode/src/vnd/vnodeOpen.c Adds pBse cleanup in vnodeOpen()’s _err path to prevent BSE handle leaks.
source/dnode/vnode/src/tsdb/tsdbCache.c Fixes LRU cache leak on tsdbOpenCache() failure by cleaning up pCache before returning an error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses memory leaks in tsdbCache and bse. The changes involve adding proper resource cleanup in error paths. In tsdbCache.c, a memory leak is fixed by cleaning up pCache if tsdbOpenCache fails. In vnodeOpen.c, a potential leak is addressed by ensuring pVnode->pBse is closed and set to NULL in the error handling block of vnodeOpen. While the changes are correct, there's an opportunity to improve code clarity in tsdbCache.c by removing a redundant assignment.

Note: Security Review did not run due to the size of the PR.

}
}

pTsdb->lruCache = pCache;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The assignment pTsdb->lruCache = pCache; is redundant here. In the error path, pCache is set to NULL within the if (code) block on line 2886. This assignment correctly sets pTsdb->lruCache to NULL. However, for better readability and to avoid confusion, it would be cleaner to set pTsdb->lruCache to NULL directly within the error handling block and remove this line.

Comment on lines +595 to +598
if (pVnode->pBse) {
bseClose(pVnode->pBse);
pVnode->pBse = NULL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It's good practice to set the pointer to NULL after freeing/closing the resource to prevent dangling pointers. This change correctly closes pVnode->pBse and sets it to NULL in the error handling path of vnodeOpen, which prevents a potential memory leak. This is a solid improvement.

@guanshengliang guanshengliang merged commit 6976382 into main Mar 10, 2026
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants