nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.96k stars 29.2k forks source link

WSL/Linux memory leak when requiring a module that can't be found #54178

Open matthew-wong1 opened 2 months ago

matthew-wong1 commented 2 months ago

Version

22.5.1

Platform

Linux DESKTOP-IV4ITK6 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

require('asdf') // or any module that doesn't exist  

How often does it reproduce? Is there a required condition?

Preload the ASan library on Linux with:

LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so node leak.js

What is the expected behavior? Why is that the expected behavior?

There should not be a memory leak

What do you see instead?

The ASan output was too long so I've included it in a file. err.txt

Additional information

No response

CGQAQ commented 1 month ago

I can not reproduce this issue

printf "require('asdf')" | node
node:internal/modules/cjs/loader:1251
  throw err;
  ^

Error: Cannot find module 'asdf'
Require stack:
- /home/cg/code/node/[stdin]
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:125:16)
    at [stdin]:1:1
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:118:14
    at [stdin]-wrapper:6:24 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/cg/code/node/[stdin]' ]
}

Node.js v22.6.0
uname -a
Linux TROILA-001553 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
matthew-wong1 commented 1 month ago

I updated my node to v22.6.0 and executed the same file using: LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so node leak.js and was still able to get the LeakSan error.

Just wanted to check if you had set the environment variable LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so? Or maybe used a different sanitizer implementation? I'm using gcc 11.4.0 if it might be something to do with the sanitizers?

Thanks!

I also tested other systems and I'm not able to reproduce on macOS or Windows.