We develop an app called DX Scanner using npm-check-updates to detect if the user has updated all dependencies or not. The DX Scanner can scan many repositories/projects simultaneously (see Promise.all) (ncu.run call).
I run the DX Scanner with a cmd yarn start https://github.com/yarnpkg/yarn and the app throws a warning
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit
so I was looking for the reason. The reason is
process.on('unhandledRejection')
here: https://github.com/tjunnone/npm-check-updates/blob/50b444ebec7f970bef34cb6d36eb1ace821116d0/lib/npm-check-updates.js#L389-L391
It can happen that more than 20 parallel scans run at the same time so the ncu runs out all 11 event listeners.
More about the behavior of the process.on in a for loop: https://stackoverflow.com/a/38225520/10826693 and https://stackoverflow.com/a/44446859/10826693.
I tried to change .on to .once but it didn't help.
I really don't want to set maxListeners to a higher value. I believe that it has a good reason to be set just for 11.
I was searching for some solutions and I have found an article about the removal of all listeners.
I would recommend to add process.removeAllListeners('uncaughtException'); to the end of run function in npm-check-updates but I am not sure about it. It's not possible to guarantee that all uncaughtException in a process is really from ncu.
I tried to remove those 3 lines in my node_modules/npm-check-updates folder and it works correctly.
Do you have any other idea how to solve this issue on the side of npm-check-updates?
We develop an app called DX Scanner using
npm-check-updatesto detect if the user has updated all dependencies or not. The DX Scanner can scan many repositories/projects simultaneously (see Promise.all) (ncu.runcall).I run the DX Scanner with a cmd
yarn start https://github.com/yarnpkg/yarnand the app throws a warningMaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limitso I was looking for the reason. The reason is
here: https://github.com/tjunnone/npm-check-updates/blob/50b444ebec7f970bef34cb6d36eb1ace821116d0/lib/npm-check-updates.js#L389-L391
It can happen that more than 20 parallel scans run at the same time so the
ncuruns out all 11 event listeners.More about the behavior of the process.on in a for loop: https://stackoverflow.com/a/38225520/10826693 and https://stackoverflow.com/a/44446859/10826693.
I tried to change
.onto.oncebut it didn't help.I really don't want to set maxListeners to a higher value. I believe that it has a good reason to be set just for 11.
I was searching for some solutions and I have found an article about the removal of all listeners.
I would recommend to add
process.removeAllListeners('uncaughtException');to the end ofrunfunction innpm-check-updatesbut I am not sure about it. It's not possible to guarantee that alluncaughtExceptionin aprocessis really fromncu.I tried to remove those 3 lines in my
node_modules/npm-check-updatesfolder and it works correctly.Do you have any other idea how to solve this issue on the side of
npm-check-updates?