lavacord/Lavacord

RangeError: Maximum call stack size exceeded

RaknaXTR opened this issue · 2 comments

I sometimes get this error when a song is opened.

events.js:263
EventEmitter.prototype.emit = function emit(type, ...args) {
                                           ^

RangeError: Maximum call stack size exceeded
    at DelayedStream.emit (events.js:263:44)
    at DelayedStream._handleEmit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:82:15)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:29:19)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)
    at PassThrough.source.emit (/root/main/node_modules/delayed-stream/lib/delayed_stream.js:30:21)

And here's a memory leak warning

(node:2272) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Player]. Use emitter.setMaxListeners() to increase limit

Could this be due to too many errors emitted in a song?

I've noticed the same issue, when a song ends it doesn't look like the Error event connected to it gets removed, Which means after 11 songs, you'd have 11 error events listening once for an error

What I did myself is add a removeListener in the song end function, to remove the error event from the song that just ended, keeping one error listener forever.
I have no idea if Jacz has a different way or people like us are handling songs the wrong way, but atleast it works

Thats one way to do it. another way would be to check when listening to events is to check whether there are listeners already so

if (!player.listenerCount("error")) player.once("error" () => do stuff);

you can even use this for the end event