lavacord / Lavacord

A easy to use Lavalink client that can be used with any discord api wrapper
Apache License 2.0
78 stars 21 forks source link

RangeError: Maximum call stack size exceeded #90

Closed ghost closed 3 years ago

ghost commented 3 years ago

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?

AGuyNamedJens commented 3 years ago

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

MrJacz commented 3 years ago

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