问题
I have an error and I don't know how to solve it. It happens only some times.
Error message:
(node:9140) MaxListenersExceededWarning: Possible EventEmitter memory leak detec
ted. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
回答1:
This error often occurs when you are using EventEmitters directly or indirectly in your code and you are creating too many in too short a period for them to be resolved -- Node detects this as a memory leak and throws an error once the Max Listener count has been exceeded.
For example, it's often common in unit tests to setup and tear-down pre-conditions before and after each test. Test runners like Mocha will often run tests in parallel, so if you have dozens of test then you can quickly run the Event Listener count over the maximum if your setup steps perform operations which emit events (e.g. Connecting to a Database).
Without your specific code, it would be difficult to pinpoint the cause, but I recommend you review your code for any Event Emitters that you may be using either directly or in modules that you are including and look for any instances where you may be inadvertently creating too many of them in parallel (e.g. through Promises or modules like async). The key is to look for places in your code where you have a lot of parallel execution such as loops with Promises.
来源:https://stackoverflow.com/questions/49946001/nodejs-maxlistenersexceededwarning