EnriqCG / rcon-srcds

A zero-dependency Typescript library for the Source/Minecraft RCON Protocol
https://www.npmjs.com/package/rcon-srcds
MIT License
60 stars 20 forks source link

Possible EventEmitter memory leak detected #1

Closed Thomas-Smyth closed 4 years ago

Thomas-Smyth commented 5 years ago

Hello,

I've been using a fork of this repository, however, this issue seems to be inherited from here.

I am using the repository to poll a server once every so often to get player count details. After around 9 .execute() calls, the following warning is thrown:

(node:12752) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit

It looks as if your code is not removing listeners after the returning the response. To test this I editted your write function to remove the .on('data', onData) just before the promise is resolved. This seems to have prevented the warning, however, I am not sure on what effect it will have on multi-packet responses. Is this something that you could look into?

Thanks in advance.

Taraman17 commented 4 years ago

Seeing the same issue. Are you still maintaining this?

Thomas-Smyth commented 4 years ago

@Taraman17 based on the lack of response to this issue I assume not.

Please refer to my fork for a possible fix... https://github.com/Thomas-Smyth/rcon/commit/8de4d8e83e657924e61ff8ce1bd0b95299d7d2b3

EnriqCG commented 4 years ago

Thanks to @Taraman17's work this issue has been finally fixed. Listeners are now being removed correctly 🎉