node-ethernet-ip icon indicating copy to clipboard operation
node-ethernet-ip copied to clipboard

Memory leak from not removing listeners on promise reject

Open jhenson29 opened this issue 5 years ago • 0 comments

Event listeners added inside of a promise are not removed on reject creating a memory leak. (node:2012) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 Multiple Service Packet listeners added. Use emitter.setMaxListeners() to increase limit

Current Behavior

Repeated calls create new listeners without removing the old ones.

Expected Behavior

...not leak memory.

Possible Solution (Optional)

Event listener should be removed prior to rejecting. Possibly just always remove listener as fist step in listener callback.

Context

Steps to Reproduce (for bugs only)

  1. Subscribe to non-existent tag.
  2. Wrap contoller.scan() in a try/catch.
  3. Wrap try/catch in while(true){}

Your Environment

  • Package version (Use npm list - e.g. 1.0.6):
  • Node Version (Use node --version - e.g. 9.8.0):
  • Operating System and version:
  • Controller Type (eg 1756-L83E/B):
  • Controller Firmware (eg 30.11):

jhenson29 avatar Sep 26 '18 00:09 jhenson29