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

memory leak, when module require error occurs #32836

Closed
lianxuify opened this issue Apr 14, 2020 · 0 comments
Closed

memory leak, when module require error occurs #32836

lianxuify opened this issue Apr 14, 2020 · 0 comments

Comments

@lianxuify
Copy link
Contributor

Environment

  • version: nodejs v14.0.0-pre
  • platform: mac

What steps will reproduce the bug?

// main.js
const count  = 100
for (var i = 0; i < count; i++) {
  try {
     require('./error-module.json')
     // require('./error-module.js')
  }catch (e) {}
}
debugger
// error-module.json
{
  json: "syntax errors, no double quotes"
}
// error-module.js
throw new Error('any module syntax error')

What is the expected behavior?

Run main.js , expected error module completely clear and willl be garbage collected.
image

What do you see instead?

It is still retained by parent module now.
image

Additional information

I discovered this in the process of solving the my service memory leak problem, which logic like:each request load the module for some reason, unfortunately module is syntax error.

I checked the source code of nodejs and found that when the module error was occurs, the golbal module cache and the resolve path cache were deleted, but the module in parent.children array was not deleted.

I solved the problem, preparing my first PR for nodejs, and looking forward to your review.

@lianxuify lianxuify changed the title memory leak, when module dependency error occurs, this useless module is not deleted in parent module: parent.children memory leak, when module require error occurs Apr 14, 2020
lianxuify added a commit to lianxuify/node that referenced this issue Apr 15, 2020
Delete useless module in parent module: parent.children array when error occuers
so that the memory can be garbage collected.

Fixes: nodejs#32836
MylesBorins pushed a commit that referenced this issue Apr 17, 2020
Delete useless module in parent module: parent.children array
when error occurs, so that it can be garbage collected.

Fixes: #32836

PR-URL: #32837
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
targos pushed a commit to targos/node that referenced this issue Apr 25, 2020
Delete useless module in parent module: parent.children array
when error occurs, so that it can be garbage collected.

Fixes: nodejs#32836

PR-URL: nodejs#32837
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
BridgeAR pushed a commit that referenced this issue Apr 28, 2020
Delete useless module in parent module: parent.children array
when error occurs, so that it can be garbage collected.

Fixes: #32836

PR-URL: #32837
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
targos pushed a commit that referenced this issue Apr 28, 2020
Delete useless module in parent module: parent.children array
when error occurs, so that it can be garbage collected.

Fixes: #32836

PR-URL: #32837
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
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 a pull request may close this issue.

1 participant