-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
vm: Script importModuleDynamically memory leak #25424
Copy link
Copy link
Closed
Labels
help wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.memoryIssues and PRs related to the memory management or memory footprint.Issues and PRs related to the memory management or memory footprint.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Metadata
Metadata
Assignees
Labels
help wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.memoryIssues and PRs related to the memory management or memory footprint.Issues and PRs related to the memory management or memory footprint.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
While investigating #21573 I was interested in understanding why we are storing the
importModuleDynamicallycallback in a weak map, as that surely means that it can be GC'd if there is an indeterminate time before theimport()function in the module is called.I may or may not have diagnosed the issue correctly, but the test case is a bug nonetheless:
main.js
Where
test.mjsexists as an ES module.Running with:
node --experimental-modules --expose-gc main.jsI get the following output:If I comment out the
gc()line or run theimport()call without a timeout the correct output is provided.This makes me think we should reconsider the use of weak maps as the storage for the dynamic callback, and rather accept that the dynamic callback should always have a lifecycle that is directly tied to the lifecycle of the module(s) it is referenced by.