NodeJS : warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit

前端 未结 1 1129
后悔当初
后悔当初 2020-12-31 18:31

I have the below code:

var schild = spawn(\'script.sh\', [\"process1\", \"process2\"]);
        schild.stderr.on(\'data\', function (data) {
                         


        
相关标签:
1条回答
  • 2020-12-31 19:00

    I believe the problem is that you're not removing the listeners when you don't need them anymore. You need to use 'schild.removeListener('exit', function)' or 'schild.removeAllListeners('exit')' when you're done with them.

    See: http://nodejs.org/api/events.html#events_emitter_removelistener_event_listener

    Of course there are scenarios where you need to have more than 10 listeners in which case you should use 'schild.setMaxListeners(0)' (0 means unlimited)

    See: http://nodejs.org/api/events.html#events_emitter_setmaxlisteners_n

    Hope it helps!

    0 讨论(0)
提交回复
热议问题