pghalliday / node-BrowserStackTunnel

https://www.npmjs.com/package/browserstacktunnel-wrapper
MIT License
17 stars 24 forks source link

Prevent EventEmitter memory leaks #23

Closed vedharish closed 8 years ago

vedharish commented 8 years ago

The issue #5 can be reproduced by trying to quit karma tests on BrowserStack (using karma-browserstack-launcher) prematurely by sending SIGINT events (Ctrl-C) multiple times trying to close the tunnel.

Karma emits an 'exit' event for each SIGINT event and karma-browserstack-launcher calls tunnel.stop for each 'exit' event. Hence, 'stop' can be called multiple times, which lead to multiple listeners for 'stop' event in the previous code.

A listener for 'stop event' should only be added if the state of the tunnel is not already 'stop' and there are no previously registered listeners for 'stop' events. This PR addresses that.

pghalliday commented 8 years ago

I was trying to get my head round this but I think i'll just take your word for it :) The change looks safe enough. Thanks