Skip to content

memory leak, when module require error occurs #32836

Closed
@lianxuify

Description

@lianxuify

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions