cannawen / dota-gsi-discord-bot

Use Dota 2's Game State Integration API to make helpful announcements in a discord voice channel
MIT License
5 stars 2 forks source link

[bug] Maximum listeners memory leak warning #71

Open cannawen opened 1 year ago

cannawen commented 1 year ago

Listening on a user's audio stream gives us this error:

2023-05-01T02:21:55.293 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-01T02:21:55.661 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-01T02:21:55.661 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-01T02:30:29.830 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit
cannawen commented 1 year ago

Tried upping the limit to 20. Perhaps this will help, if there are legitimately more people who want to listen?

cannawen commented 1 year ago

Upping the value to 20 dosn't help xd

2023-05-08T23:52:17.473 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 21 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-08T23:52:19.463 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 21 close listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-08T23:52:19.463 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 21 error listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit
cannawen commented 1 year ago
2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at _addListener (node:events:587:17)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at AudioReceiveStream.addListener (node:events:605:10)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at Readable.on (node:internal/streams/readable:887:35)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at AudioReceiveStream.once (node:events:649:8)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at pipe (node:internal/streams/pipeline:362:9)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at pipelineImpl (node:internal/streams/pipeline:323:25)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at Function.pipeline (node:internal/streams/pipeline:151:10)

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at /app/build/discord/speechToText.js:89:26

2023-05-13T19:53:07.623 app[e2865644f6e686] yyz [info] at new Promise (<anonymous>)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at _addListener (node:events:587:17)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at AudioReceiveStream.addListener (node:events:605:10)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at Readable.on (node:internal/streams/readable:887:35)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at AudioReceiveStream.once (node:events:649:8)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at pipe (node:internal/streams/pipeline:362:9)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at pipelineImpl (node:internal/streams/pipeline:323:25)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at Function.pipeline (node:internal/streams/pipeline:151:10)

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at /app/build/discord/speechToText.js:89:26

2023-05-13T19:53:12.824 app[e2865644f6e686] yyz [info] at new Promise (<anonymous>)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at _addListener (node:events:587:17)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at AudioReceiveStream.addListener (node:events:605:10)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at Readable.on (node:internal/streams/readable:887:35)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at destroyer (node:internal/streams/pipeline:46:10)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at pipelineImpl (node:internal/streams/pipeline:223:38)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at Function.pipeline (node:internal/streams/pipeline:151:10)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at /app/build/discord/speechToText.js:89:26

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at new Promise (<anonymous>)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at Object.transcribe (/app/build/discord/speechToText.js:72:12)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at _addListener (node:events:587:17)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at AudioReceiveStream.addListener (node:events:605:10)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at Readable.on (node:internal/streams/readable:887:35)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at pipelineImpl (node:internal/streams/pipeline:241:14)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at Function.pipeline (node:internal/streams/pipeline:151:10)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at /app/build/discord/speechToText.js:89:26

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at new Promise (<anonymous>)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at Object.transcribe (/app/build/discord/speechToText.js:72:12)

2023-05-13T19:53:13.347 app[e2865644f6e686] yyz [info] at _SpeakingMap.<anonymous> (/app/build/discord/rules/startVoiceSubscription.js:85:36)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] (node:521) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at _addListener (node:events:587:17)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at AudioReceiveStream.addListener (node:events:605:10)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at Readable.on (node:internal/streams/readable:887:35)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at eos (node:internal/streams/end-of-stream:191:10)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at destroyer (node:internal/streams/pipeline:50:19)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at pipelineImpl (node:internal/streams/pipeline:223:38)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at Function.pipeline (node:internal/streams/pipeline:151:10)

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at /app/build/discord/speechToText.js:89:26

2023-05-13T19:53:14.388 app[e2865644f6e686] yyz [info] at new Promise (<anonymous>)

More logs

cannawen commented 1 year ago

In testing locally, I added some logs to count the number of listeners when we close the pipeline---

            console.log(
                `${userId} stopped speaking with ${source.listenerCount(
                    "end"
                )} listeners`
            );

The majority of the time we have 2 listeners, but sometimes we get up to 6.

169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
2023-05-14 09:40:01 info  [TTS]     hello 
169619011238232073 started speaking
169619011238232073 stopped speaking with 3 listeners
2023-05-14 09:40:07 error [TTS]     Problem with transcription, 1696190112 talking for too long 
169619011238232073 started speaking
169619011238232073 started speaking
169619011238232073 stopped speaking with 4 listeners
169619011238232073 stopped speaking with 4 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 started speaking
169619011238232073 stopped speaking with 6 listeners
169619011238232073 stopped speaking with 6 listeners
2023-05-14 09:40:25 error [TTS]     Problem with transcription, 1696190112 talking for too long 
2023-05-14 09:40:25 error [TTS]     Problem with transcription, 1696190112 talking for too long 
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
2023-05-14 09:40:32 info  [TTS]     David birthday. 
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
2023-05-14 09:40:39 info  [TTS]     yeah yeah yeah 
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 stopped speaking with 2 listeners
169619011238232073 started speaking
169619011238232073 started speaking
169619011238232073 stopped speaking with 6 listeners
169619011238232073 stopped speaking with 6 listeners
2023-05-14 09:40:54 error [TTS]     Problem with transcription, 1696190112 talking for too long 
2023-05-14 09:40:54 error [TTS]     Problem with transcription, 1696190112 talking for too long 

There's still something sketchy going on with the library, sometimes the connection.receiver.speaking.on("start" callback gets called multiple times for a single voice stream. To fix it we might have to debounce listening on our side, or dig into the library further? Or just leave it because it's not that big of a deal ...

cannawen commented 1 year ago

OK, so it looks like the error gets triggered in certain environments more than others. Still not sure how to reproduce, but it kinda seems like a bigger deal if this is going to be happening all the time...

errors.txt