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.
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.