oclif/cli-ux

MaxListenersExceededWarning

Closed this issue · 1 comments

@RasPhilCo @elbandito

We started getting this

(node:41715) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:254:17)
at process.addListener (events.js:270:10)
at process.once (events.js:299:8)
at Object. (/usr/local/lib/node_modules/sfdx-cli/node_modules/cli-ux/lib/index.js:96:9)
at Module._compile (/usr/local/lib/node_modules/sfdx-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Module._load (internal/modules/cjs/loader.js:555:12)
at LazyLoader.loadIfNeeded (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/lazy-require/lib/LazyLoader.js:63:19)
at Object.get (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/lazy-require/lib/LazyLoader.js:219:28)
at module.exports (/usr/local/lib/node_modules/sfdx-cli/node_modules/@oclif/command/flush.js:3:12)
at /usr/local/lib/node_modules/sfdx-cli/bin/run:39:40

process.once('exit', async () => {

Looks like every time cli-ux is imported it will create an exit event listener. So by default after importing cli-ux 11 times you will get this event emitter leak?

jdx commented

this is an issue with the lazy loader. Node doesn't run the module code multiple times:

$ node -e 'for (i=0; i<1000; i++) require("cli-ux")'
(nothing output)