voxeet / comms-sdk-web-getting-started

Getting Started with the Dolby.io Communications SDK for Web.
https://docs.dolby.io/communications-apis/docs/getting-started-with-the-javascript-sdk
MIT License
17 stars 18 forks source link

Warning: (node) warning: possible EventEmitter memory leak detected #31

Closed Schaeri closed 1 year ago

Schaeri commented 1 year ago

We are currently testing the Dolby Video Call Communication API for a new application. In the process, we noticed that there are warnings when we keep opening and exiting the chat.

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. voxeet-sdk_3.9.0.js:2:720464 console-export-2023-3-20_9-11-42.txt

Our code is based on the Get Started Sample: https://github.com/dolbyio-samples/comms-sdk-web-getting-started/blob/main/video-calls/final/index.html. We have taken the javascript code for the prototype unchanged. The question now is whether this is really a bug because of memory leaks? Or if the sample still contains bugs and not all resources are released.

j12y commented 1 year ago

I haven't been able to reproduce what you observed yet but will keep investigating.

This might just be a byproduct of it being sample code though. There is a trade-off in keeping the code simple enough to explain the basic concepts without going into too much detail about a production application. For instance, if you are using a web framework like Angular, React, VueJS, etc. each have their own approach to maintain button state. So in your production application you would prevent end-users from joining the session over and over again by deactivating the join button until the session is cleanly closed.

A more flushed out example that demonstrates state management, etc. much like a final application can be found here: https://github.com/dolbyio-samples/comms-app-react-videocall

I'll experiment a bit more to see if we can improve the sample.

Schaeri commented 1 year ago

j12y thanks for the reply. I'll try to adapt the example and post it here when I find the time.

j12y commented 1 year ago

In speaking with others from the team, I will also add that the warning can be ignored. JavaScript will emit the warning even when there is a small (in your case 11) number of event subscription handlers. If this were growing uncontrolled it could be an indication of a memory leak but that is not the case in this scenario.

Here's a bit more information on the underlying warning: https://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n