Skip to content
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

node-api: Memory leak fix for RefBase::Delete(RefBase* reference) #44339

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nagendra5
Copy link

@nagendra5 nagendra5 commented Aug 22, 2022

Memory leak fix: Added missing_finalize_ran.

This is to fix the memory leak. calling finalizer and not setting _finalize_ran to true will cause a memory leak.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/node-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. labels Aug 22, 2022
@legendecas
Copy link
Member

Would you mind sharing a re-production with the memory leak?

@nagendra5
Copy link
Author

nagendra5 commented Oct 7, 2022

Would you mind sharing a re-production with the memory leak?

Usually, it takes a lot of time to create a sample app that follows a certain sequence to reproduce the memory leak. This leak is always reproducible in my app but I am not supposed to share the code base. Please check the usage of _finalize_ran variable. Don't you think after calling _env->CallFinalizer(fini, _finalize_data, _finalize_hint); we have set '_finalize_ran' to true?.

memory leak got fixed in our app after setting _finalize_ran to true.

@legendecas
Copy link
Member

legendecas commented Oct 10, 2022

I am still skeptical about if this change is the actual solution that settled the memory leak you mentioned.

The _finalize_ran is set to true just after the procedure of calling into user finalizer: https://github.com/nodejs/node/blob/main/src/js_native_api_v8.cc#L570. If _delete_self or is_env_teardown is set, _finalize_ran is being ignored in RefBase::Delete (https://github.com/nodejs/node/blob/main/src/js_native_api_v8.cc#L509).

FWIW, we are working on simplifying the finalization procedures at #44141.

@nagendra5 nagendra5 changed the title Memory leak fix for RefBase::Delete(RefBase* reference) node-api: Memory leak fix for RefBase::Delete(RefBase* reference) Oct 10, 2022
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

This PR needs to wait for the question raised in #44339 (comment) to be resolved before proceeding.

@mhdawson
Copy link
Member

@legendecas do you think your changes related to reference have addressed the issue and that this PR is no longer needed/applicable?

@legendecas
Copy link
Member

Right, telling from the change sites I believe they are relevant. @nagendra5 would you mind verifying if the leak is still observable in the latest build of Node.js v18.14.0 or later versions? Thank you.

@mhdawson
Copy link
Member

@nagendra5 are you able to validate the issue still occurs with recent versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants